Node:Slices, Next:, Previous:Hash Functions, Up:Associative Arrays (Hashes)


It turns out you can slice hashes just like you were able to slice arrays. This can be useful if you need to extract a certain set of values out of a hash into a list.

     use strict;
     my %table = qw/schmoe joe smith john simpson bart/;
     my @friends = @table{'schmoe', 'smith'};   # @friends has qw/joe john/

Note the use of the @ in front of the hash name. This shows that we are indeed producing a normal list, and you can use this construct in any list context you would like.