Hello, I use LWP to read a page and it creates a hash. When I try to dereference the hash it prints _protocolHTTP/1.1_content at the top of my output. What am I doing wrong? Thank you.

#!/usr/bin/perl use warnings; use diagnostics -verbose; #prints "_protocolHTTP/1.1_content" at the top ot the page use LWP 5.64; $nextpage = 'http://www.amazon.com/index.htm'; my $browser = LWP::UserAgent->new; my $P = $browser->get($nextpage); $P->content_type, " document!\n"; print "Content-Type: text/html\n"; print "\n\n"; #print $P; - prints HTTP::Response=HASH(0x1388fb0)} print %$P; #--- prints page but has a header "_protocolHTTP/1.1_c +ontent" close(STDOUT); exit true;

Update

Not really sure how to restore my original post. But the gist was at the top of every page I would see a hash instead of the page content. I added the %$P to try to dereference the hash but instead got "_protocolHTTP/1. 1_content" at the top of each page. Then Apple Fritter pointed me in the right direction and it now works. Thanks again guys.

# approximation of the original code $nextpage = 'http://www.Amazon.com/index.htm'; use LWP 5.64; my $browser = LWP::UserAgent->new; $P = $browser->get($nextpage); $P->content_type, " document!"; print "\n\n"; # print $P; print %$P; #attempt to dereference close(STDOUT); exit true;

Thank you Apple Fritter. You did point me in the right direction and for that I am grateful. After 4 hours of scouring the manual and trying 'solutions' that I barely understood, here is what finally worked. Posted to help the next person who is as lost as me. Lesson learned: Perl is not for the weak of heart.

use LWP::UserAgent; $nextpage = 'http://www.amazon.com/index.htm'; my $ua = new LWP::UserAgent; my $response = $ua->get($nextpage); unless ($response->is_success) { die $response->status_line; } my $P = $response->decoded_content(); if (utf8::is_utf8($content)) { binmode STDOUT,':utf8'; } else { binmode STDOUT,':raw'; } print "Content-Type: text/html\n"; print "\n\n"; print $P; close(STDOUT); exit true;

In reply to Unintended header _protocolHTTP/1.1_content by StatPac

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.