Problem with syntax getting array elements
- From: "Dave Saville" <dave@xxxxxxxxxxxxxxx>
- Date: Wed, 6 Jun 2012 08:32:18 +0000 (UTC)
Given
my @x = qw(a b c);
print "$x[2]\n";
($a, $b) = @x[1,2];
print "$a $b\n";
Gives me
c
b c
But
my %h;
$h{a} = [1,2,3];
print $h{a}[2]."\n";
my ($a, $b) = $h{a}[1,2];
print "$a $b\n";
Gives
3
Use of uninitialized value $b in concatenation (.) or string
3
I have tried all sorts of brackets braces etc. in various combinations
but I cannot get the anonymous array contained in the hash to work
like the first example. What silly thing am I missing?
TIA
--
Regards
Dave Saville
.
- Follow-Ups:
- Re: Problem with syntax getting array elements
- From: Rainer Weikusat
- Re: Problem with syntax getting array elements
- From: Tim Watts
- Re: Problem with syntax getting array elements
- Prev by Date: Re: Activestate Perl 5.16
- Next by Date: Re: Problem with syntax getting array elements
- Previous by thread: Activestate Perl 5.16
- Next by thread: Re: Problem with syntax getting array elements
- Index(es):
Relevant Pages
|