Hi all,

Was just playing around with some of the code in Sean M Burke's Perl and LWP (nice book, BTW) and encountered some unexpected behaviour with one of the examples from chapter three which uses $response->current_age(). Here's the program:

#!/usr/bin/perl use warnings; use strict; use LWP; my $browser = LWP::UserAgent->new(); my $response = $browser->get('http://www.perl.com/images/tabs/tab-perl +blk.gif', ':content_cb' => \&hex_dump, ':read_size_hint' => 123, ); print "Waiting a bit...\n"; sleep 10; my $age = $response->current_age(); print "$age\n"; # debug my $days = int($age/86400); $age -= $days * 86400; my $hours = int($age/3600); $age -= $hours * 3600; my $mins = int($age/60); $age -= $mins * 60; my $secs = $age; print "The document is $days days, $hours hours, $mins minutes, and $s +ecs seconds old.\n"; sub hex_dump { my ($data, $response) = @_; print length($data), " bytes:\n"; print ' ', unpack('H*', substr($data,0,16,'')), "\n" while length $data; return; }

On my machine (SuSE Linux 8.0, Perl 5.6.1, LWP 5.66), this program outputs "The document is 0 days, 8 hours, 57 minutes, and 28 seconds old."

But according to the HTTP::Response man page, $response->current_age

calculates the "current age" of the response as specified by draft-ietf-http-v11-spec-07 section 13.2.3. The age of a response is the time since it was sent by the origin server. The returned value is a number representing the age in seconds.

I'm puzzled as to why this program does not say the document is 10 seconds old. The only thing I can think of is that the "current age" of the document (about 9 hrs) is roughly the same as the time difference between my location (Austria) and O'Reilly in CA. Could that be the reason, or is it something else entirely?

Thanks in advance, mooseboy


In reply to $response->current_age() behaving unexpectedly by mooseboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.