Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Question regarding perl subroutine

by sureshsmr (Initiate)
on Jul 15, 2012 at 21:07 UTC ( #981926=note: print w/replies, xml ) Need Help??

in reply to Re: Question regarding perl subroutine
in thread Question regarding perl subroutine

Hi John Davies, Thanks a lot! That was good catch. Now I am getting a different error as below:

/usr/local/bin/perl Can't call method "agent" on an undefined value at + line 158.

Here is the code on line 158:

my $ua->agent("Mozilla/5.0"); #my $ua->agent("");

is the syntax for calling "agent" method ok? I am not sure what tool is on our unix server. Any suggestions ? Thanks Suresh

Replies are listed 'Best First'.
Re^3: Question regarding perl subroutine
by afoken (Abbot) on Jul 15, 2012 at 21:11 UTC

    $ua is not what you think. It is undefined, probably because the code above lacks error checks. See Basic debugging checklist.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^3: Question regarding perl subroutine
by davies (Parson) on Jul 15, 2012 at 21:28 UTC

    No, that syntax cannot be right. Looking at the code you posted originally, I see:

    my $ua= new LWP::UserAgent; #my $ua->agent("Mozilla/5.0"); my $ua->agent("");

    You seem to be trying to use strict;, which is good (see my home node), but without understanding what it does. PerlIntro ( has a section on variable scoping that it might help you to understand. my creates a new instance of a variable. You may have seen examples of messages telling you that a declaration masks a previous declaration. This is telling you that you have re-initialised a variable name, which is unlikely to be what you want. I think what you want is something like:

    my $ua= new LWP::UserAgent; $ua->agent("Mozilla/5.0");

    but as I don't even know what LWP is, this is a pretty wild guess. might be another good read.


    John Davies

Re^3: Question regarding perl subroutine
by monsoon (Pilgrim) on Jul 15, 2012 at 21:18 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981926]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-06-20 14:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.