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

Dear monks,

Following the manual, I displayed the exit code and status line from a response object I got using the lwp::useragent.
I thought the response should totally comply the rules from a common HTTP::Response structure, so I'm fetching its information as following:

$res = $ua->request($req);
print "$res->code\:\t$res->status_line";
print "$res->message";

However, it gave me such display:
HTTP::Response=HASH(0x8dd8414)->code:        HTTP::Response=HASH(0x8dd8414)->status_line
HTTP::Response=HASH(0x8dd7e40)->message

On other hand, I can get the content from those methods by de-referencing their output, but I guess that may not be the formal way.
So, can anyone please let me know what's wrong with using the '->code/->message' on the response? Or maybe I have some misunderstanding about the response structure generated from lwp::useragent instead of directly from the http::response?


Thanks in advance

  • Comment on Getting exit code and status from useragent response obj

Replies are listed 'Best First'.
Re: Getting exit code and status from useragent response obj
by hippo (Archbishop) on Jun 10, 2015 at 12:23 UTC
    print "$res->code\:\t$res->status_line";

    Method calls inside quotes won't be recognised as such. Instead:

    print $res->code . ":\t" . $res->status_line;
      Thanks a lot for the quick response. Yes after move it out of the quotes, seems that works just fine! :)