numeric values in a list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • a

    numeric values in a list

    I would like to do the following:
    my list = (100,2,5); #create a list
    my @sorted = sort {$a<=>$b} list; #sort ascending
    #want @sorted = (2,5,100)

    What's wrong with my list with numeric values?
    Thanx


  • Jim Gibson

    #2
    Re: numeric values in a list

    In article <LI_Ve.198264$H k.97930@pd7tw1n o>, <a@mail.com> wrote:
    [color=blue]
    > I would like to do the following:
    > my list = (100,2,5); #create a list
    > my @sorted = sort {$a<=>$b} list; #sort ascending
    > #want @sorted = (2,5,100)
    >
    > What's wrong with my list with numeric values?[/color]

    Nothing in theory. It is hard to say for sure since you have not posted
    actual code that compiles and runs. Try doing that and maybe someone
    will be able to help you.

    And, as I explained last week, this newgroup is defunct. Try
    comp.lang.perl. misc in the future (but be sure and adhere to the
    guidelines for posting to that group).

    Like this:

    #!/usr/local/bin/perl
    #
    use strict;
    use warnings;
    my @list = (100,2,5);
    my @sorted = sort {$a<=>$b} @list;
    print "sorted: @sorted\n";

    .... produces ...

    sorted: 2 5 100

    Posted Via Usenet.com Premium Usenet Newsgroup Services
    ----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    ----------------------------------------------------------
    Best Usenet Service Providers 2025 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

    Comment

    Working...