Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Numeric sorting WITHOUT <=>

by Marshall (Abbot)
on Oct 10, 2012 at 04:42 UTC ( #998130=note: print w/replies, xml ) Need Help??

in reply to Re: Numeric sorting WITHOUT <=>
in thread Numeric sorting WITHOUT <=>

my ($min) = keys(%jetsons); This is the number of keys in %jetsons.
This is not the min.

Replies are listed 'Best First'.
Re^3: Numeric sorting WITHOUT <=>
by AnomalousMonk (Chancellor) on Oct 10, 2012 at 13:08 UTC
    my ($min) = keys(%jetsons); This is the number of keys in %jetsons.

    Actually, it's a randomly (insofar as the hashing algorithm is random) chosen key from the hash. The assignment is in list context and seeds the min/max finder loop that follows.

    >perl -wMstrict -le "my %jetsons = qw(aa 1 bb 2 cc 3 dd 4 ee 5); my ($min) = keys %jetsons; print $min; " cc

    Update: ikegami's code works. (Never doubt a Pope.)

Re^3: Numeric sorting WITHOUT <=>
by ikegami (Pope) on Oct 10, 2012 at 18:11 UTC
    # keys in scalar context: Number of keys. my $min = keys(%jetsons); # keys in list context: List of keys. First one is assigned my ($min) = keys(%jetsons);
      My mistake.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998130]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-11-25 00:22 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (354 votes). Check out past polls.