in reply to LWP::Simple, a bug in head() function?

The results were the similar through my tests, so I did a little digging, and found that the problem seemed to come when there was no expires time. The expires time gets returned in the form
HTTP::Date::str2time($response->header('Expires'))
Taking a quick look in Date.pm, near the top of the str2time function is the line
return unless defined $str;
Changing this line to instead read
return undef unless defined $str;
seems to produce the desired result, but I don't know enough offhand about this module to know whether that would affect any other desired behavior.

Replies are listed 'Best First'.
RE: Re: LWP::Simple
by plaid (Chaplain) on Mar 14, 2000 at 23:52 UTC
    I seem to keep losing my cookie somehow. Anyways, I posted the above, so direct any responses to me.
      Is not just from expires field, also when content_length and modified_time are missing the result are "corrupted".
      Please take a more carefully look at the run output that i posted:
      The idea is to obtain something like:
      
      content_type <> content_length <> last_modified <> expires <> server
      
      and i never obtained server as last field (after last <> separator),
      the position of server was 3 and, respectively, 4 (never 5 :()(indexing
      from 1)
      
      All that three requested urls has no expires, and first
      was a directory listing (meaning no content_length and modified_time)
      

      Thanks.
        I'm working on a similer project and I get no errors
        on this, I'm not sure why its not working for you.
        I've formated the code a bit differtly, but nothing
        has changed really.


        #!/usr/bin/perl -w #url_touch.pl program file use strict; use LWP::Simple; my $url = $ARGV[0]; my $url_head; my @list; foreach $url_head(head($url)) { $url_head = "Not Given" unless defined $url_head; push( @list, $url_head); } my ($content_type, $document_length, $modified_time, $expires, $server +) = @list; print ">>$content_type<< "; print ">>$document_length<< "; print ">>$modified_time<< "; print ">>$expires<< "; print ">>$server<<\n";
        --- END_OF_FILE


        I do know that you have to use a fully qualifed URL for this to work

        work.

        www.webadept.net/index.html

        won't work, I have to use the
        http://www.webadept.net/index.html for it to work.
        here is the command and output...

        tigger$ perl url_touch.pl http://www.cjsportscards.com/index.html


        >>text/html<< >>13168<< >>982047528<< >>Not Given<< >> ConcentricHost-Ashurbanipal/2.0 (XO(TM) Web Site Hosting)<<

        Hope this helps..

        Glenn Hefley
        www.lucidmatrix.com
        The last modified time is calculated from the same str2time function that the expires time is. Changing the one line inside Date.pm should fix both of those problems. The missing content length on the first test of yours doesn't seem to be a problem, as it's undef when there isn't one.