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

Well, my question boils down to the following few lines, but I suspect that it's a <duck>bug in Perl 5.6</duck> :
use base qw(Exporter); *isa = \&UNIVERSAL::isa; print isa({}, 'HASH'); # Output under perl 5.6 : Undefined subroutine &main::isa called a +t - line 4. # Output under perl 5.005_03: 1
If I comment out the use base line, or change the glob name from isa to anything else, it works fine. Any ideas why this is happening?

Replies are listed 'Best First'.
Re: use base qw(Dazed Confused)
by Fastolfe (Vicar) on Jan 30, 2001 at 06:12 UTC
    I don't know why it's happening, but adding the following line after your 'use base' line fixes it:
    use subs 'isa';
Re: use base qw(Dazed Confused)
by Adam (Vicar) on Jan 30, 2001 at 06:07 UTC
    Well, I get the same results as you.

    But I am curious about one thing, Why are you doing this? Importing the UNIVERSAL method like that is odd. UNIVERSAL::isa() is an OO method. Anything that isn't a blessed object should be handled with ref, blessed objects have UNIVERSAL::isa as a method, and it should be called as such:

    use strict; use CGI; my $q = CGI->new(); # $q now "isa" CGI object. print $q->isa( 'CGI' ) ? "Yes it is\n" : "Nope\n"; print $q->isa( 'DBI' ) ? "Yes it is\n" : "Nope\n";
      LOL, I knew someone would ask that eventually :) Well, I have a function that takes a parameter of any sort (array ref, string, hash, object, etc...), and depending on the type of the param, it does different things. Without knowing if the parameter has been blessed or not, I cannot say:
      $param->isa('Foo')
      since that can return an error. So instead, I have to use:
      UNIVERSAL::isa($param, 'Foo');
      Which is, of course, alot to type, hence the alias.

      Update: Oh, and I forgot to mention that it wasn't exactly my idea:

      These subroutines should not be imported via use UNIVERSAL qw(...). If you want simple local access to them you can do *isa = \&UNIVERSAL::isa; to import isa into your package.
      That was taken from the <cough> UNIVERSAL.pm documentation ;)
Re: use base qw(Dazed Confused)
by Beatnik (Parson) on Jan 30, 2001 at 12:23 UTC
    Recently a guy on IRC noted the following : "According to my calculations, my code is right and the script is wrong". Needless to say, it was a newbie.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.