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

Re: Printing a hash in a specific order?

by artist (Parson)
on Mar 15, 2003 at 16:23 UTC ( #243312=note: print w/ replies, xml ) Need Help??

in reply to Printing a hash in a specific order?

Another approach

my @records; $records[1] = { a => 1, d=>4, b=> 2, c=> 3}; $records[2] = { a => 11, d=>14, b=>12}; # didn't define 'c' here $records[3] = { a => 123, d=>10, e=>200, c=> 21, d=>9888 }; # differen +t order, 'b' absent my @keys = qw( a c b); # only want to print a c and b foreach my $record (@records){ print join "\t" => map { $_, length($record->{$_}) < 3 ? $record->{$_} : substr($record->{$_},0,1)} grep { defined $record->{$_}} @keys, "\n"; print "\n"; }
a	1	c	3	b	2
a	11	b	12
a	1	c	21

Comment on Re: Printing a hash in a specific order?
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-11-26 01:01 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (695 votes), past polls