John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Isn't there a way to get a list of things from a hash? Consider
[ $x{a}, $x{b}, $x{c}, $x{d} ]
I seem to remember seeing a syntax somewhere that used @x{...} like we use for an array. Am I remembering right?

Replies are listed 'Best First'.
Re: Hash slice?
by Enlil (Parson) on Feb 16, 2004 at 08:56 UTC
    something like this?
    my %hash = ( a => 1, b => 2,c => 3, d =>4); my @list = @hash{'a','b','d'}; print @list;

    For more info look at perldata particularly the part about slices

    -enlil

Re: Hash slice?
by rob_au (Abbot) on Feb 16, 2004 at 08:54 UTC
    @list = @x{ qw( a b c d ) }

    See perldata for details.

     

    perl -le "print unpack'N', pack'B32', '00000000000000000000001011000011'"