Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all. yesturday i wrote a small script to loop through link from a webpage, it worked fine.. but today it doesnt want to work :/
my @links = $mechObject->links(); foreach my $link (@links) { print "$link->url"; }
WWW::Mechanize::Link=ARRAY(0x1ca7c1c) WWW::Mechanize::Link=ARRAY(0x1ca7c1c)->url

Replies are listed 'Best First'.
Re: confusing error >:(
by tobyink (Canon) on May 12, 2012 at 12:23 UTC

    This:

    $link->url

    ... is a method call. Method calls don't interpolate in double-quoted strings. Try:

    my @links = $mechObject->links(); foreach my $link (@links) { print $link->url; }

    Aside: there is actually a special trick for getting method calls (in fact, arbitrary code) to interpolate in strings though:

    print "Here it is: @{[ $link->url ]}!\n"
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: confusing error >:(
by Anonymous Monk on May 12, 2012 at 09:15 UTC
    So it worked a day ago, you changed nothing and now it doesn't work? Stop lying. Stop trying to game google. Use their API.
      lying? :/ that was so dumb i cant think of a reply to it :/ the code is there you cant miss it, read it, try it.. if you know perl you'd know if there was something wrong and wouldnt have to assume im lying (which makes no sense atall)

        I would assume the "lying" is about this part:

        it worked fine.. but today it doesnt want to work

        You will need to find out what you changed, and either undo that change, or fix that change. There is nothing we can do to help you, because we don't know how it worked before, nor how it fails now.

        Also, Google does not like getting scraped automatically. Use their published APIs.

Re: confusing error >:(
by Anonymous Monk on May 12, 2012 at 09:08 UTC
    this also doesnt work:
    $mechObject = WWW::Mechanize->new( autocheck => 1 ); $mechObject -> get('http://www.google.co.uk/search?q='.$queryStrin +g.'&num=10&hl=en&client=firefox-a&rls=org.mozilla:en-GB:official&chan +nel=np&prmd=imvns&ei=CCGtT-jcEeiw0QXRgaGoCQ&start=100&sa=N&biw=1440&b +ih=738'); foreach my $link ($mechObject->links) { print "$link->url\n"; }
    it used to work.. just makes no sense now? :/