i'm trying to split values that i'm getting using Web::Scraper. However, i seem to be overwriting my hash? I'm not sure how this can be. Following is my code:

#!/usr/bin/perl use strict; use warnings; use Web::Scraper; use Data::Dumper::Simple; my( $infile ) = $ARGV[ 0 ] =~ m/^([\ A-Z0-9_.-]+)$/ig; my $page = scraper { process '//*/div[@id="Results"]/table/tr/td', 'table[]' => scraper +{ process '//span', 'name' => '@id', 'attr' => '@title'; }; process '//*//table[@id="Documents"]/tr', 'docs[]' => scraper { process '//tr', 'attr' => '@title'; }; }; open(FILE, "< $infile" ); my $content = do { local $/; <FILE> }; my $res = $page->scrape( $content ) or die "Can't define content to parser $!"; # print Dumper( $res ); my %values; for my $data ( @{$res->{ table } } ) { next unless $data->{ name } and $data->{ attr }; foreach my $line (split /\n/, $data->{ attr } ) { %values = split /:/, $line; } print "$data->{ name }\t $data->{ attr }\n\n" ; } print Dumper( %values ); #print $content;

the output that i'm looking to work with is:

Name: value Name2: value2 etc

also, this is only my second option. the author of the Web::Scraper package gives an example of adding functionality in his function, but i don't understand how to return the data. his example is:

my $scraper = scraper { process 'a[rel~="tag"]', 'tags[]' => sub { my $uri = URI->new($_->attr('href')); my $label = (grep length, split '/', $uri->path)[-1]; $label =~ s/\+/%20/g; uri_unescape($label); }; };

In reply to loop split into a hash by ag4ve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.