Perl libwww--LWP::Simple

Parv parv at pair.com
Sun Sep 4 16:58:02 PDT 2005


in message <20050904230401.9653.qmail at web54501.mail.yahoo.com>,
wrote Charles Maner thusly...
>

Could you please not post your reply before the quoted text?


> Hi Parv--thanks for the reply.  My code, on all three
> platforms, is:
> 
> ##### Begin Code ##########
> use strict 'vars';
> use strict 'subs';
> 
> use LWP::Simple;
> 
> LWP::Simple::getstore("http://biz.yahoo.com/i/","tickers.html")
> or die("Website not found!\n");
> 
> open TICKERS, "tickers.html";

You should check the return value of open(), else you will get bogus
error from close() if the file does not exist.


> my @tickers = <TICKERS>;
> 
> print "@tickers\n";
> 
> close TICKERS;
> 
> exit;
> ##### End Code ##########

When i run the above code i get the page intended for a robot; below
are the first few lines ...

  <html><head><title>Yahoo! Finance Company and Fund
  Index</title></head><body><center><!-- Sp
  aceID=0 robot -->
  </center><center><p><!-- SpaceID=0 robot -->
  <table><tr align=center><td><!-- SpaceID=0 robot -->


... working alright.

Given (from LWP::Simple pod) ...

  getstore($url, $file)
    Gets a document identified by a URL and stores it in the file. The
    return value is the HTTP response code.


... you need to check the HTTP return code from getstore() which is
DIFFERENT from perl return values.  Say, if getstore() returns 404,
above code will continue to work past the close() (if tickers.html
already exists) till the exit().

I say, just use the LWP::UserAgent module and get better/easier/more
control.


  - Parv

-- 



More information about the freebsd-ports mailing list