Perl how to dereference object

A script suddenly stop working, it is using LWP::Useragent call as $req.

When printing $req->content it is showing:


How to call it to get the actual text?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First, you need to discover what is in the reference and what you want to extract.  There are a number of ways to find that.  One easy way of my choice is this:

Include the following
use Data::Dumper;

And then to print the value contained in this ref
print Dumper($ref);

Now question becomes how to dereference it.
Suppose $ref contains itemA which contains subItemA
How would you get subItemA
my $item = $ref->{'itemA'}->{'subItemA'};

Another example
Suppose it is a reference to a list, listA.  Here is how you would get this list
@mylist = @{$ref->{'listA'}};
Can you post your code?  It sounds like you may be doing something like this:

  print "$req->content";

when you meant to do this:

  print $req->content;

or this:

  printf "This is the content: %s", $req->content;

The content of $req->content is a method call.  You can't embed it within a string.  Perl doesn't do interpolation of method calls.  Just the variables themselves.  So,

  print "$req->content" is really "${req}->content"

Your $req variable is converted to a scalar (your HTTP::Response=HASH(0x86727c0)) and then '->content' is tacked on.
freshgrillAuthor Commented:
 How would I log it?

How would I rewrite: system ("echo \"$res->content\">>/tmp/paymentcomplete.log");
Typically, not with echo

open LOG, ">>/tmp/paymentcomplete.log";
print LOG $res->content;
close LOG;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if you really wanted to go with echo then maybe...

$content = $res->content;
$content =~ s/"/\\"/g;
system(qq(echo "$content" >> /tmp/paymentcomplete.log));
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.