in reply to Re^6: WWW-Search module that works
in thread WWW-Search module that works

OK, tutorial time. Here's the code on the WWW::Search page.

my $sQuery = 'Columbus Ohio sushi restaurant'; my $oSearch = new WWW::Search('AltaVista'); $oSearch->native_query(WWW::Search::escape_query($sQuery)); $oSearch->login($sUser, $sPassword); while (my $oResult = $oSearch->next_result()) { print $oResult->url, "\n"; } # while $oSearch->logout;

The second line, the one that contains the new call is what I call a constructor. It should either return an object (and thus $oSearch will be defined) or undef if Something Bad Happened.

That's the first check. Run the perl debugger, go past that line, then dump the value of $oSearch and see if it's undef or a real object. If it's undef then Something Bad Has Happened and you need to check that your network connection is working, or see if there are any other problems connecting to the Internet.

If it reports that things are good, then we move on to the results .. as you step through the loop, you should see some stuff get returned. Or, perhaps nothing will be returned because there's nothnig to be found.

I can't make it any simpler than that. If this makes no sense to you, then perhaps (and I mean this is the nicest possible way) Perl is not the language for you.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^8: WWW-Search module that works
by coder57 (Novice) on Jun 14, 2007 at 15:01 UTC
    While I read through the perl debug manual, can you clarify the above code works for you as it is? do you get printed results on new lines, for the search "Columbus Ohio sushi restaurant" ?
        While I read through the perl debug manual, can you clarify the above code works for you as it is?

      I cannot confirm the code works for me, because I don't have that module installed. But I don't *have* to have that module installed to be able to explain to you how to get started, using code from the module's own POS.

      Perlmonks is all about helping someone reasonably computer literate get through some of the bumpier parts of the language and/or the community, assuming a decent amount of effort on the part of the initiate.

      This is by now my fourth reply to your original query, and I've spent some time trying to help you. All you need to do is put the code into a script, run it with perl -d yourScriptHere.pl, step through a few lines (n for next), and dump the value of some variables (x $yourVariable), and, based on those results, move forward with your learning.

      Or someone else will pick up this particular falling torch ..

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

        so far :
        C:\Perl\bin>perl -d ysam5a.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(ysam5a.pl:7): my $sUser; DB<1> x $sUser 0 undef DB<2> n main::(ysam5a.pl:8): my $sPassword; DB<2> x $sPassword 0 undef DB<3> n main::(ysam5a.pl:10): my $sQuery = 'Columbus Ohio sushi restaurant'; DB<3> x my $sQuery 0 undef DB<4>
        The exact code is:
        #!/usr/bin/perl use strict; use warnings; use WWW::Search; my $sUser; my $sPassword; my $sQuery = 'Columbus Ohio sushi restaurant'; my $oSearch = new WWW::Search('AltaVista'); $oSearch->native_query(WWW::Search::escape_query($sQuery)); $oSearch->login($sUser, $sPassword); while (my $oResult = $oSearch->next_result()) { print $oResult->url, "\n"; } # while $oSearch->logout;
        Pls if you could install the module and verify for yourself, because I am not the only one who says it no longer works.