Can"t call method error

Can"t call method error

am 13.08.2011 01:58:30 von Jeffrey Joh

I'd like to include code so that if I get the following error=2C the script=
will just ignore it and keep running:

=20

"Can't call method "attr" on an undefined value at abcde.pl line 2"

=20

Does anyone know of such a code?

=20

Jeff =

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Can"t call method error

am 13.08.2011 02:08:18 von Feng He

You will always be able to check the return status of a method call,
something like:

my $obj = Some::Module->new
or die "can't create object from Some::Module";

Regards.



On Sat, Aug 13, 2011 at 7:58 AM, Jeffrey Joh wrote:
>
> I'd like to include code so that if I get the following error, the script will just ignore it and keep running:
>
>
>
> "Can't call method "attr" on an undefined value at abcde.pl line 2"
>
>
>
> Does anyone know of such a code?
>
>
>
> Jeff
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Can"t call method error

am 13.08.2011 04:33:22 von Uri Guttman

>>>>> "FH" == Feng He writes:

FH> You will always be able to check the return status of a method call,
FH> something like:

FH> my $obj = Some::Module->new
FH> or die "can't create object from Some::Module";

please learn to bottom post. i now have to comment on your answer and
also the OP's but it is ordered incorrectly.

so your answer doesn't help the OP. his error is coming from perl after
he thinks he has an object. maybe it is coming from somewhere else and
he can't check the constructor or maybe the object was created but got
lost in scope or something.

FH> On Sat, Aug 13, 2011 at 7:58 AM, Jeffrey Joh wrote:
>>
>> I'd like to include code so that if I get the following error, the script will just ignore it and keep running:
>>
>> "Can't call method "attr" on an undefined value at abcde.pl line 2"

first off, you shouldn't be calling a method unless you know you have an
object. as i commented above you should see why this is happening and
fix it there. this can be handled but that isn't solving the real
problem. you don't have an object where you (and perl) think you should.

if this is actually the important problem, then you can wrap the method
call in an eval block (not eval string) and that will trap the error and
you can continue. but you should really fix the problem of not having an
object.

uri

--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/