Beginner wrote:
Hi all,Is it possible to make a hash slice like so my %hash; @[EMAIL PROTECTED] = [EMAIL PROTECTED]; My efforts suggest not: #!/bin/perl use strict; use warnings; use Data::Dumper; my @keys = qw(fe fi fo thumb); my @vals = 1..4; my %hash; @[EMAIL PROTECTED] = [EMAIL PROTECTED]; print Dumper(\%hash); $VAR1 = { 'ARRAY(0x226d54)' => [ 1, 2, 3, 4 ] }; Am I missing something or isn't this possible?
Hey Dermot It's certainly possible, but I'm not sure why you've taken a reference to your key and value arrays. [EMAIL PROTECTED] is a single scalar value, as is [EMAIL PROTECTED], so you're creating a single hash element. Perl has had to stringify the reference to @keys as Perl hash keys must be strings. The hash value is a reference you your @vals array which contains the values 1 through 4 as Dumper shows. That you need is simply @[EMAIL PROTECTED] = @vals; which you will find has the effect you expect. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
