in reply to Re: printing hashes
in thread printing hashes

My favorite is:
print join(', ', map { $_ . ' => '. $hash{$_} } keys %hash), "\n";
-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^3: printing hashes
by thcsoft (Monk) on May 06, 2005 at 04:16 UTC
    i absolutely agree with you, but propose to sort the hash keys prior to mapping the result:
    print join(', ', map { $_ . _ => ' . $hash{$_} } sort { $a cmp $b } ke +ys(%hash), "\n";


    @ anonymus monk:
    the sort block is what sort() performs automatically, so it's just a placeholder for any other sorting routine.
    perldoc -f sort will give you some examples and advices.

    language is a virus from outer space.