Mega Code Archive

 
Categories / Perl / Hash
 

Obtain the list of keys and display each key-value pair

%presidents = ( George => "A",                 Abe    => "B",                 Thomas => "C",                 Harry  => "D" );        @keys = keys( %presidents ); while ( $key = pop( @keys ) ) {    print "$key => $presidents{ $key }\n"; }