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

Okay, I must admit that I have not read the perldoc files for these functions for v5.6.1, but in the v5.6.0 perldoc entries it did not go into the semantic differences between these items.

So what exactly do each of these do different? What instances would I use either one? Is there an FAQ, article, or literary material somewhere I should look at?

  • Comment on semantics differences, &ref and &UNIVERSAL::isa()

Replies are listed 'Best First'.
Re: semantics differences, &ref and &UNIVERSAL::isa()
by educated_foo (Vicar) on May 18, 2002 at 16:52 UTC
    I don't know where to look for this in the docs, but isa handles inheritance, whereas ref does not. For example:
    package A; sub new { my $c = shift; $c = ref $c || $c; bless {}, $c; } package B; @ISA=qw(A); sub new { my $c = shift; $c = ref $c || $c; bless {}, $c; } package main; my $b = new B; print "b isa A = ", $b->isa('A'), "\n"; print "ref b = ", ref($b), "\n";
    /s
      ref (and isa) would be good places to look at for docs. :)
      You have moved into a dark place.
      It is pitch black. You are likely to be eaten by a grue.

        the ref and isa docs still did not seem to help.. the only thing I reall got was:

        ref returns the base type that an object is, but not a package/object-type
        &UNIVERSAL::isa returns true or false is the first argument is an instance of of the package of the second argument...

        Now back to one of my other questions: when would I use either?