Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Need some help with Hashes and formatting

by Laurent_R (Canon)
on Jun 25, 2014 at 06:16 UTC ( [id://1091133]=note: print w/replies, xml ) Need Help??


in reply to Need some help with Hashes and formatting

It is really useless to use intermediary arrays. Use directly your hash:
foreach my $key (keys %hash) { print "$key \t $hash{$key} \n"; }
You might also take a look at the each function to fetch directly the key/value pairs.

Get into the habit of using directly hashes rather than going into the trouble of using intermediary arrays, that's the only way to ge used to hashes and really leverage on their power.

Edit: adding an example with the each function:

while ( my ($key, $value) = each %hash) { printf "%10s\t%10s\n", $key, $value; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found