in reply to Arrays of hashes which have arrays
As the other monks have answered your question, I thought I might offer a tip. When printing the contents of an array, or stringifying an array in general, it's a lot easier (and more idiomatic) to use join.
So instead of:
my $yy = $test->{'divs'}; foreach my $xx (@$yy) { print $xx."\n";}
try:
The extra parens are required to prevent print being interpreted as a function and seeing only the join, not the extra "\n".my $yy = $test->{'divs'}; print ((join "\n", @$yy) . "\n");
You also might want to explore more about {} syntax for dereferencing structures. The Camel Book has an excellent overview of the various syntaxes. Here's an example, eliminating the need for $yy:
Of course, it can be argued that these sorts of idioms reduce legibility. It's a matter of taste.foreach my $xx (@{$test->{divs}}) { print $xx."\n";} print ((join "\n", @{$test->{divs}}) . "\n");
--Clinton
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Arrays of hashes which have arrays
by johngg (Canon) on Jan 27, 2009 at 22:56 UTC |