This outputs:#!/usr/bin/perl use warnings; use strict; use LWP::Simple qw(); use LWP::UserAgent; use HTML::Treebuilder; use HTTP::Request; my $raw_html = LWP::Simple::get("http://www.perlmonks.org") || die + ("$!\n"); # print $raw_html; my $tree = HTML::TreeBuilder->new; $tree->parse($raw_html); $tree->eof; #$tree->dump; my @image_array=(); my %image = (); foreach my $image ($tree->look_down("_tag", "img")){ push (@image_array, \%image); } use Data::Dumper; print Dumper(@image_array);
If I modify the original code to this you can see it outputs an array for each image in the html:$VAR1 = {}; $VAR2 = $VAR1; $VAR3 = $VAR1; $VAR4 = $VAR1;
This version outputs this:#!/usr/bin/perl use warnings; use strict; use LWP::Simple qw(); use LWP::UserAgent; use HTML::Treebuilder; use HTTP::Request; my $raw_html = LWP::Simple::get("http://www.perlmonks.org") || die + ("$!\n"); # print $raw_html; my $tree = HTML::TreeBuilder->new; $tree->parse($raw_html); $tree->eof; #$tree->dump; my @image_array=(); my %image = (); foreach my $image ($tree->look_down("_tag", "img")){ print $image; }
I am trying to build an array of these hashes that I will be using later in my script. Thanks in advance for any help!!HTML::Element=HASH(0x221d7b8)HTML::Element=HASH(0x2240b30)HTML::Elemen +t=HASH(0x2240be4)HTML::Element=HASH(0x22421e8)
Edited by Chady -- linked node id.
In reply to problems constructing an array of hashes by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |