in reply to Re^2: 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.

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

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

Replies are listed 'Best First'.
Re^4: Help Getting WWW::Mechanize Link reference array to output to STD_OUT.
by tfredett (Sexton) on Jul 03, 2012 at 19:51 UTC

    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

        So I took your suggestions here, and first off, thanks for the help, I also have been able to progress forward, kinda.

        I have changed how I create the Mechanize object to provide autocheck and to show_progress both set to true. It provided me with some other insight that I have worked through and resolved.

        However, I have hit the same problem, I have even tried dereferencing the array created, to know avail. I still receive the error of the array or variable being unintialized. I have attempted this by attempting to print it via the previous loop, and by providing this line taken from your code.

        my $temp1 = $mech->find_all_links( text_regex => qr/Server-/i ); my @temp2 = shift $temp1; print "@temp2\n";
        Perhaps I am just missing something super obvious, since I appear to be in the correct scope, and I am trying to use the one created, even though it appears not feasibly possible. Any other suggestions?