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

Greetings, fellas.

I'm trying to write a Win32 Multiple Search script using WWW::Search.

So I guess I'd do it like this:
#!/usr/bin/perl -w require WWW::Search; while ($term = <>) { chomp $term; @se = ('AltaVista, Excite, Infoseek, Lycos'); foreach $se (@se) { $search = new WWW::Search('$se'); $search->native_query(WWW::Search::escape_query($term)); print "\n\nResults from $se :\n\n"; while ($result = $search->next_result()) { print $result->url, "\n"; } } }
Well the problem here - as the experienced brothers probably already seen - it's that $se is not parsed, so it trys to run literally $search = new WWW::Search('$se'), instead of $search = new WWW::Search('AltaVista'), for an example.

If I try it with double quotes or no quotes at all I still receive an error.

How can I solve this? I guess it's pretty simple, but I'm stucked. My best guesses would be using eval or q// but I couldn't make it work with these solutions either.

TIA,

my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");

Replies are listed 'Best First'.
Re: Making a WWW::Search loop
by gav^ (Curate) on May 07, 2002 at 21:11 UTC
    You probably meant:
    @se = ('AltaVista', 'Excite', 'Infoseek', 'Lycos'); $search = new WWW::Search($se);
    You might want to consider running it under use strict and changing it to:
    foreach my $se (qw(AltaVista Excite Infoseek Lycos)) { my $search = new WWW::Search($se); # etc
    Hope this helps...

    gav^

Re: Making a WWW::Search loop
by Kanji (Parson) on May 07, 2002 at 21:13 UTC

    If that's cut n' pasted, you're setting @se to be one long string of comma seperated SEs, when you probably meant to do ...

    @se = ('AltaVista', 'Excite', 'Infoseek', 'Lycos'); # or @se = qw(AltaVista Excite Infoseek Lycos);

    After which, the double-quoting (or better yet, no quoting: new WWW::Search($se)) method should work.

        --k.


Re: Making a WWW::Search loop
by particle (Vicar) on May 07, 2002 at 21:10 UTC
    use double quotes... or better yet, no quotes at all.
    $search = new WWW::Search($se);</code>

    Update: i'm sorry, why doesn't it work without quotes? what's the error?

    Update 2: unstrike the first bit, combine it with @se = ('AltaVista', 'Excite', 'Infoseek', 'Lycos'); and you're set. actually, throw in a little strict and warnings, and you shouldn't run into this very often.

    ~Particle *accelerates*