djerius has asked for the wisdom of the Perl Monks concerning the following question:
Whilst trying to explain to someone the benefits of
eval { $x->isa( $class ) }to determine if an object belongs in a class, I embarrassingly came across the following behavior, which I could not explain.
This, surprisingly, runs without error. If instead, I make $x a number:use strict; use warnings; my $x = 'string'; $x->isa('huh?');
I get the expected error:use strict; use warnings; my $x = 3; $x->isa('huh?')
Can't call method "isa" without a package or object reference at foo.pl line 5.Why should a string have access to UNIVERSAL methods while a number doesn't? I've tried this with Perl 5.10.1 and 5.12.2.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: strings->can->isa but numbers->can't?
by moritz (Cardinal) on Apr 26, 2012 at 15:32 UTC | |
by djerius (Beadle) on Apr 26, 2012 at 17:37 UTC | |
|
Re: strings->can->isa but numbers->can't?
by Anonymous Monk on Apr 26, 2012 at 15:16 UTC | |
|
Re: strings->can->isa but numbers->can't?
by ikegami (Patriarch) on Apr 26, 2012 at 15:39 UTC | |
by Anonymous Monk on Apr 26, 2012 at 18:13 UTC | |
by choroba (Cardinal) on Apr 26, 2012 at 22:04 UTC |