in reply to problems constructing an array of hashes
touse Data::Dumper; print Dumper(@image_array);
You will see the type of structure you are aiming for.use Data::Dumper; print Dumper \@image_array;
On a seperate topic though since you are my %image outside the foreach block you will find that all the elements pushed onto @image_array will be a reference to the SAME hash. (also because just because $image is a hash_ref, apart from the similarities in the name it does not relate in any way to %image.)I doubt this is what you intend. From your second bit of code I would assume what you are looking for is something like:
#!/usr/bin/perl use warnings; use strict; use LWP::Simple; use LWP::UserAgent; use HTML::Treebuilder; use HTTP::Request; use Data::Dumper; my $raw_html = LWP::Simple::get("http://www.perlmonks.org") || die("$!\n"); my $tree = HTML::TreeBuilder->new; $tree->parse($raw_html); $tree->eof; my @image_array; foreach my $image ($tree->look_down("_tag", "img")){ push @image_array, $image; } print Dumper \@image_array;
update: Zaxo's solution above nicely skips the accomplishes the same population of the @image_array without the foreach loop.
-enlil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: problems constructing an array of hashes
by Anonymous Monk on May 13, 2004 at 18:21 UTC |