U
usenet
Kindly consider the following code which illustrates my question:
#!/usr/bin/perl
use strict; use warnings;
use Data:umper;
my %hash;
$hash{1}{'foo'} = 'one';
$hash{2}{'foo'} = 'two';
$hash{3}{'foo'} = 'three';
my @foos;
push @foos, $hash{$_}{'foo'} for keys %hash;
print Dumper \@foos;
__END__
As you can see, I have created an array containing the values of the
various "foo" keys within the hash. But that seems a bit kludgy. It
seems I ought to be able to do something similar to this (with
slicing):
my @foos = @hash{keys %hash}{'foo'};
But I can't seem to figure out how to implement this approach.
I would appreciate some not-so-kludgy pointers. Thanks!
#!/usr/bin/perl
use strict; use warnings;
use Data:umper;
my %hash;
$hash{1}{'foo'} = 'one';
$hash{2}{'foo'} = 'two';
$hash{3}{'foo'} = 'three';
my @foos;
push @foos, $hash{$_}{'foo'} for keys %hash;
print Dumper \@foos;
__END__
As you can see, I have created an array containing the values of the
various "foo" keys within the hash. But that seems a bit kludgy. It
seems I ought to be able to do something similar to this (with
slicing):
my @foos = @hash{keys %hash}{'foo'};
But I can't seem to figure out how to implement this approach.
I would appreciate some not-so-kludgy pointers. Thanks!