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

Re: two questions that come together into one grand unified question

by IraTarball (Monk)
on Oct 15, 2001 at 23:28 UTC ( #118972=note: print w/replies, xml ) Need Help??


in reply to sorting and comparing hashes

I just wanted to put my spit in the pot too. So you know...
%hash = sort %hash;
is valid under strict but unlikely to do anything usefull. You get the hash flattened into a list, the list get's sorted, and then assigned to hash. A list assigned to a hash uses consecutive pairs and key/value pairs. I wrote a quick bit of code.
use strict; use warnings; my %hash = ( thing1 => 'one thing', thing2 => 'leads to another', All => 'is great and glorious', ); print "$_ => $hash{$_}\n" for keys %hash; %hash = sort %hash; print "\n"; print "$_ => $hash{$_}\n" for keys %hash;
Output is
thing2 => leads to another All => is great and glorious thing1 => one thing leads to another => one thing thing1 => thing2 All => is great and glorious
I can't think of a reason you would want to do this. I just wanted to throw it into this thread since it is kinda (but not really) used in the initial code.

Goip,
Ira,

"So... What do all these little arrows mean?"
~unknown

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2019-05-22 05:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (138 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!