Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Stupid, yet simple, sort question

by Kage (Scribe)
on Oct 24, 2001 at 20:44 UTC ( [id://121181]=note: print w/replies, xml ) Need Help??


in reply to Stupid, yet simple, sort question

Okay...I got 3 answers...all three sound right...but I don't know which to use..I need the most efficient one..
#1: sort{ $a->{users} ,<=> $b->{users} } @locations #2 for my $loc ( sort { $a->{users} <=> $b->{users} } @locations ) #3 foreach $loc (reverse sort { int($a) <=> int($b) } @locations)
Which one is the most efficient one? I need one that can take at least 3,000 different ranks...thats the stress limit of my script and it must be able to handle the stress limit..

Replies are listed 'Best First'.
Re: Re: Stupid, yet simple, sort question
by davorg (Chancellor) on Oct 24, 2001 at 20:48 UTC

    None of them will work, as they all assume that you're using hard references - which you aren't.

    Unless I've completely misunderstood your code.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      As noted in chatter, davorg was correct about Kage using symbolic referencees but was incorrect in thinking that the syntax $a->{key} does not work when $a isn't a "hard" reference (that is, when $a simply contains the name of some global hash variable).

      Of course, use strict would prevent it from working, but that also prevents ${$a}{key} from working.

              - tye (but my friends call me "Tye")

        Let the record show that tye is 100% correct and my assumption that $a->{key} implied hard references was 100% wrong.

        Let the record further show, however, that in my opinion allowing that syntax to work with symbolic references is a very bad idea :)

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you don't talk about Perl club."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://121181]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found