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

I've inherited some Perl code. Decyphering it has prooved harder than I had imagined. I beseech my fellow brothers for help. Please consider this code:
$url = "https://www.example.com/reports/newIssues/changeParams2.jsp"; $error {newoff_entry} {url} = $url; $req = HTTP::Request->new(POST => $url); $req->content_type('application/x-www-form-urlencoded'); $cjar->add_cookie_header($req); $req->header(userid => $user); $req->content("userid=$user&SessionId=$sessid&language=en"); $ua->{'timeout'} = $timeout; $t0 = new Benchmark; $resp = $ua->send_request($req); $t1 = new Benchmark; $error {newoff_entry} {rt} = timediff($t1, $t0); $cjar->extract_cookies($resp); #$debug = $resp->as_string(); if (($resp->as_string() =~ /RR\s+codes/i)||($resp->as_string() =~ /$ss +l_bug/)){ $error {newoff_entry} {rc} = 'ok'; }else{ $error {newoff_entry} {rc} = 'error'; }
There are many sections similar to the one above. Sometimes, the error below is returned instead of the expected results.
bad time value () at /usr/lib/perl5/5.8.0/Benchmark.pm line 510. Can't call method "cpu_p" on an undefined value at /usr/lib/perl5/5.8. +0/Benchmark.pm line 512.
I suspect that there may be an error acquiring the web content. Perhaps I need some error checking but, I don't have enough experience with the UserAgent to understand where to begin.

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Benchmarking LWP::UserAgent requests
by leocharre (Priest) on Apr 12, 2006 at 15:04 UTC

    Yo.. $cjar is being expected to be an object instance. Do you know about Object Oriented Programming? At least a rough idea? You gotta read about this please. This script/program whatever.. is using objects, and it seems that at least this one ($cjar) is not being made, summoned, or something.

    This is a tiny chunk of meaningless code. I think maybe having more of it up here would help. This could be a mess- If this is a large app, you should seek possibly using the author as a resource. Can't you ask for that from your employer?

    also, it looks to me as if this may not be using strict. in my humble opinion, this could be really sh1++y code. Just how big is this program? And yeah, code can be really crappy, uncommented, totally devoid of any karma for helping inheritors. Hope that gives incentive to do nice code for whomever inherits our babble ! :)