On Thu, Mar 12, 2009 at 01:27, Chap Harrison <c...@pobox.com> wrote: > On Mar 11, 2009, at 11:51 PM, Chas. Owens wrote: > >> Dereference the hashref as an arrayref then ask for the keys: >> >> #!/usr/bin/perl >> >> use strict; >> use warnings; >> >> my %hash = ( adams => {} ); >> >> my @keys = qw/a ar af aw/; >> my @values = (1, 19, 13, 11); >> >> @{$hash{adams...@keys} = @values; >> >> use Data::Dumper; >> >> print Dumper \%hash; > > > Thank you for both a solution and several other useful tips as well! > > It's still not intuitive to me why we FIRST "convert" the hash to an array, > and THEN ask for keys - keys being hash-ish, rather than array-ish sorts of > things. (I've said that badly.) What exactly are the elements of the array > @{$hash{adams...@keys} ? snip
It isn't really becoming an array. A better way to think of it is that $ means we expect one value back from the data structure: my $scalar = $array[0]; my $scalar = $hash{foo}; and @ means we expect to get many values back from the data structure my @result = @array[0 .. 5]; my @result = @hash{qw/foo bar baz/}; of course, you have to look at the context to determine what happens: my $length = @array; -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/