Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to print key and value of hash in a list

by johngg (Canon)
on May 23, 2011 at 08:58 UTC ( #906270=note: print w/replies, xml ) Need Help??


in reply to How to print key and value of hash in a list

Some examples using the "babycart" (@{ [ ... ] }) operator to interpolate a bit of code into a double-quoted string.

knoppix@Microknoppix:~$ perl -E ' > %hash = ( a => 1, b => 2, c => 3 ); > say qq{@{ [ values %hash ] }}; > say qq{@{ [ sort { $b <=> $a } values %hash ] }}; > say qq{@{ [ map $hash{ $_ }, sort keys %hash ] }};' 3 1 2 3 2 1 1 2 3 knoppix@Microknoppix:~$

I hope this is helpful.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2023-06-09 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (35 votes). Check out past polls.

    Notices?