http://www.perlmonks.org?node_id=979755


in reply to Re: Help Getting WWW::Mechanize Link reference array to output to STD_OUT.
in thread Help Getting WWW::Mechanize Link reference array to output to STD_OUT.

So first off, sorry, I forgot to run a search, I am normally more on top of things like that :).

I checked out both links, and of the two, Fetching links with WWW::Mechanize seemed to be the one relevant to me as WWW::Mechanize and following multiple links results in the problem of getting bad links.

In Fetching links with WWW::Mechanize, the OP, was having the same issue I am, however I have tried the solutions in the two posts there already. I have both searched through WWW::Mechanize::Link and have tried to use the built in functions (as seen in the foreach loop) as well as the other post using a similar foreach loop that I have, (I have tried that foreach loop as well, to make sure that it was not just the loop.) Perhaps I am using the reference incorrectly?

  • Comment on Re^2: Help Getting WWW::Mechanize Link reference array to output to STD_OUT.

Replies are listed 'Best First'.
Re^3: Help Getting WWW::Mechanize Link reference array to output to STD_OUT.
by Anonymous Monk on Jul 03, 2012 at 19:41 UTC

    Perhaps I am using the reference incorrectly?

    No, not really. While you're not coping with scoping you're using find_all_links... correctly

    Try it yourself

    $ mech-dump --links http://example.com /_css/2008.1/reset-fonts-grids.css /_css/2008.1/screen.css

    What version of mechanize do you have?

    Upgrade upgrade upgrade

      I am currently using WWW::Mechanize version 1.72 (read: latest version).

      I will check out the link you provided, and return with an update on my findings, thanks for the help!

      UPDATE: so after looking through the links provided above, I am rather confused by what you mean by saying "While you're not coping with scoping you're using find_all_links... correctly" I have looked, and my scope appears to be within the same block, and as such should be able to see it during execution time, which yields true, if you take the return of find_all_links and place it in a scalar, as it returns a reference to an array. So perhaps I am just blind, but I am missing what you mean. Would you mind expanding on what you mean, in an effort to help me understand?

        Yup, I meant to link to the Tutorials category Variables and Scoping

        Function which don't take arguments are bad

        Your original code perltidyd

        How to write it so its coping with scoping :)

        sub Main { my $mech = ...; ...; Get_Success( $mech ); ...; } sub Get_Success { my( $mech ) = @_; #prints the success result and starts a new line. print $mech->success(); print "\n"; }

        Or better still, use the existing features of Mechanize

        #!/usr/local/bin/perl -- use strict; use warnings; use WWW::Mechanize 1.72; Main( @ARGV ); exit( 0 ); sub Main { my $search = shift; my $mech = WWW::Mechanize->new( qw/ autocheck 1 show_progress 1 /); $mech->get( $search ); my @serverLinks = $mech->find_all_links( url_regex => qr/_css/i ); for my $link( @serverLinks ) { for my $member ( qw/ url text name tag / ){ no warnings 'uninitialized'; print $link->$member, "\n" ; } } } __END__ $ perl dumplinks http://nowhere.example.com ** GET http://nowhere.example.com ==> 500 Can't connect to nowhere.exa +mple.com:80 (Bad hostname) (1s) Error GETing http://nowhere.example.com: Can't connect to nowhere.exam +ple.com:80 (Bad hostname) at dumplinks line 15. $ perl dumplinks http://example.com ** GET http://example.com ==> 302 Found ** GET http://www.iana.org/domains/example/ ==> 200 OK /_css/2008.1/reset-fonts-grids.css link /_css/2008.1/screen.css link /_css/2008.1/print.css link

        Also error is  my $Input = ("LastName, FirstName"); you can see how if you use Basic debugging checklist