In the future please only post the relevant code. Trim your examples down to the minimal case that still demonstrates the problem. See How (not) to ask a question - Only Post Relevant Code

Here is a somewhat trimmed down version:

use warnings; use LWP 5.64; use URI; use HTML::LinkExtor; my $base = "http://search.ebay.com/ws/search/SaleSearch"; my $browser = LWP::UserAgent->new; my $url = URI->new($base); $url->query_form( 'satitle'=> 'learning perl', 'sacat'=> 267, ); my %data = (); # set up the link handler sub my $link_extor = HTML::LinkExtor->new(\&handle_links); #get search results my $response = $browser->get($url); #get the links $link_extor->parse($response->content); exit; ###################################### sub handle_links { my ($tag, %links)=@_; if ($tag eq 'a') { foreach my $key (keys %links) { #search for links with Viewitem if ($key eq 'href') { if ( $links{$key} =~ m/ViewItem/) { #get the item number from the link $links{$key} =~ m/item=(\d+)/; printf "links{%s} = %s\n",$key,defined $links{$key +} ? $links{$key} : 'undef'; if (!defined $1) { die "\$1 is undefined."; } $data{$1}=$links{$key}; } } } } }
Output:
links{href} = http://cgi.ebay.com/Learning-Perl-by-Randal-L-Schwartz-1 +997_W0QQitemZ220021417901QQihZ012QQcategoryZ2228QQssPageNameZWDVWQQrd +Z1QQcmdZViewItem $1 is undefined. at test.pl line 43.
The warning is being printed because while $links{$key} =~ m/ViewItem/ matches, $links{$key} =~ m/item=(\d+)/ does not.

To avoid warnings like this you should always check that the regex was succesful before checking $1.


In reply to Re: Scraping Ebay by imp
in thread Scraping Ebay by lv211

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.