Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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
    No.
    # 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);
      Correct.
      My mistake.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998130]
help
Chatterbox?
[marto]: well, their mother let them sleep till 15:00 & 12:00 last week, which didn't help them adjust :P
[Corion]: I was "productive" over the weekend in the sense that I revived my old "Perlmonks on SQLite" code, which likely means I can get a test instance back up running on my webhost. Small steps :)
[Corion]: marto: Ow, no, that doesn't help at all :)
[choroba]: Related to the new release, anyone could explain this or this tester report?
[Discipulus]: hello crew! marto thanks for the message: but I how can I help? i'm testing cpan Padre atm problem with Client::Debug
[choroba]: I don't happen to have 5.10.0 nor 5.8.5 handy...
[Corion]: Hmm - I would say the 5.8.5 is a broken installation / corrupt tarball download, and the 5.10.0 is really weird, and maybe a bug in that version of Perl

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2018-06-25 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?