Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Modules / October 2006



Tip: Looking for answers? Try searching our database.

No connection using LWP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Praveen - 27 Oct 2006 22:30 GMT
Hi,
I have just started learning LWP by using O'Relliy book. I wrote this
as my first program. When I executed it, nothing comes out and the
program kept on running. Ultimetly I have to cancle the program using
cntrl-C.
Here is the code:

use strict;
use LWP::Simple;

my $catalog = get("http://www.yahoo.com");
my $count = 0;
while ($catalog =~ -m{sports}gi){
    print "$_";
    $count++;
   
    }
print "$count\n";

Please let me know what is wrong. I am
John W. Krahn - 28 Oct 2006 00:29 GMT
> I have just started learning LWP by using O'Relliy book. I wrote this
> as my first program. When I executed it, nothing comes out and the
> program kept on running. Ultimetly I have to cancle the program using
> cntrl-C.
> Here is the code:

You should enable the warnings pragma, it would have told you:

Use of uninitialized value in pattern match (m//) at -e line 9.

use warnings;

> use strict;
> use LWP::Simple;
>
> my $catalog = get("http://www.yahoo.com");
> my $count = 0;
> while ($catalog =~ -m{sports}gi){
                    ^
                    ^
You have a unary minus sign in front of the match operator so that is the same
as writing:

while ( $catalog =~ -( $_ =~ m{sports}gi ) ) {

>     print "$_";

You are not putting anything into $_ so with warnings enabled this will also
give you a warning:

Use of uninitialized value in concatenation (.) or string at -e line 10.

>     $count++;
>    
>     }
> print "$count\n";

John
Signature

Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.