On 9 Nov 2007 at 20:04, Jenda Krynicky wrote: > From: "Beginner" <[EMAIL PROTECTED]> > > On 9 Nov 2007 at 16:35, Jenda Krynicky wrote: > > > > > From: "Beginner" <[EMAIL PROTECTED]> > > > > #!/bin/perl > > > > > > > > use strict; > > > > use warnings; > > > > use Data::Dumper; > > > > > > > > my @keys = qw(fe fi fo thumb); > > > > my @valone = 1..4; > > > > my @valtwo = 10..14; > > > > my %hash; > > > > @[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo]; > > > > > > [...] creates an array reference. You want > > > > > > @[EMAIL PROTECTED] = ( [EMAIL PROTECTED],[EMAIL PROTECTED]); > > > > > > Probably. Though it will only set the values for 'fe' and 'fi', > > > because I only specify two values. > > > > > > > What I was attempting was to have each key to be assigned the > > coresponding items from the array. So it might look like something > > like: > > > > $VAR1 = { > > 'fe' => [ > > 1, > > 10 > > ], > > 'fi' => [ > > 2, > > 11, > > ], > > 'fo' => [ > > 3, > > 13, > > ], > > 'thumb' => [ > > 4, > > 14, > > ] > > }; > > @[EMAIL PROTECTED] = map [$valone[$_], $valtwo[$_]] (0..$#valone); > > > The map produces a list of arrayrefs, each referenced array contains > one item from @valone and one from @valtwo. The 0th element of the > result, the 0th elements of @valone and @valtwo, etc.
Now there you go again with a beautifully simple use of map that does exactly what I want (do you need a comma before (0..$#valone)?). I notice now that I wrote my example wrong. Each array was meant to have 4 items in (sorry Rob). So it should have been my @valone = 1..4; my @valtwo = 11..14; There seems to be a bit of confusion over what I was trying to achieve. I typed out the output from Dumper I was expecting because I was/am not entirely sure what terms to use. The above operation looks like a hash slice to me albeit with another operator (map) involved. Thanx for the help. Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/