Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:
I am stuck with a particular piece of Perl and have tried everything I can think of to solve the problem.
This is the test code I've been playing with:
#!/usr/bin/perl -w $table={}; for $i (1..10){ $table{$i} = $i}; for $i (1..10){ if ($i%2==0){$table{$i}{shape}='rect'} else {$table{$i}{shape}='circle'} $table{$i}{coords} = [0,1,2,3,4,5,6,7,8,9]; } foreach $key ( keys %table ){ print "Key $key Value $table{$key}\n"; print "Shape $table{$key}{shape}\n"; foreach(@{$table{$key}{coords}}){print "$table{$key}{co +ords}[$_]"}; print "\n"; };
My problem lies in the fact that I want to be able to take a slice of said array. I'd rather be able to do something along the lines of $table{$key}{coords}[0,3] for example to get just the first 4 elements of said array in the hash.
Is this only possible by running a loop over this array?
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Correct syntax to access an array slice within a hash within a hash
by jeffa (Bishop) on May 07, 2002 at 23:42 UTC | |
|
Re: Correct syntax to access an array slice within a hash within a hash
by broquaint (Abbot) on May 07, 2002 at 23:31 UTC | |
|
Re: Correct syntax to access an array slice within a hash within a hash
by snowcrash (Friar) on May 07, 2002 at 23:42 UTC | |
|
slice of ( ref of HoH dereferenced as array )
by particle (Vicar) on May 08, 2002 at 00:05 UTC | |
|
Re(Amel): Correct syntax to access an array slice within a hash within a hash
by dsb (Chaplain) on May 08, 2002 at 01:37 UTC | |
|
Re: Correct syntax to access an array slice within a hash within a hash
by Popcorn Dave (Abbot) on May 08, 2002 at 05:24 UTC |