Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: question about: my $a AND sort {$a <=> $b} keys %hash

by Laurent_R (Canon)
on Aug 06, 2015 at 09:29 UTC ( [id://1137636]=note: print w/replies, xml ) Need Help??


in reply to Re: question about: my $a AND sort {$a <=> $b} keys %hash
in thread question about: my $a AND sort {$a <=> $b} keys %hash

Don't lexicalize them with my $a or my $b if you want to be able to us +e them in the sort() comparison block or function.
But, on the other hand you can localize them when needed:
$ perl -we ' local $a = 1; @h = sort {$a <=> $b} keys %hash; print "@h\n";> %hash = map { $_ , undef } 0 .. 3; @h = sort {$a <=> $b} keys %hash; print "@h\n"; ' 0 1 2 3

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-24 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found