on Thu, 09 May 2002 17:18:26 GMT, [EMAIL PROTECTED] wrote:
> I have an unusual question: If I have an anonymous array stored in
> a hash, is there a more graceful way of iterating through each
> item in the anonymous array than using a counter? i.e.,
>
> @all_records{q} = [1, 2, 3]
Note that this syntax is incorrect. You want
$all_records{q} = [1,2,3];
instead. If you turn on warnings, perl will warn you about this with
'Scalar value @all_records{q} better written as $all_records{q}'
> $j = 0;
> while ($all_records{q}->[$j]) {
> print $all_records{$i}->[$j];
> $j++;
> }
In fact, it is not different from an ordinary array, as long as you
use the correct dereferencing syntax:
For an ordinary array, you could use (the ultra compact):
my @array = (1,2,3);
print for @array;
or the more elaborate (if you want e.g. one element per line):
my @array = (1,2,3);
for my $element (@array) {
print "$element\n";
}
For an anonymous array stored as a hash element, this becomes:
print for @{$all_records{q}};
and
for my $element (@{$all_records{q}}) {
print "$element\n";
}
--
felix
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]