in reply to Re^2: Code from perlboot not working as expected
in thread Code from perlboot not working as expected

Ahh, I missed that part of the OP - sorry. That's happening because the first object in @_ when you invoke a method via an object is the object, not the package name. Thus your $class variable contains the scalar reference and when you print $class you stringify that reference. One way of handling that is to use ref. Something like:

my $self = shift; my $class = ref($self) || $self;

If $self contains a blessed reference, ref will return the package name. If it contains a string, ref will return undef and hence the || will return the original string.

I personally prefer perltoot to perlboot. But both are certainly worth working through.

Replies are listed 'Best First'.
Re^4: Code from perlboot not working as expected
by davies (Monsignor) on May 17, 2010 at 15:10 UTC
    Perfect. I actually tried perltoot first, but got horribly confused by constructs like my $class = ref($self) || $self;. Thanks to your explanation, I now understand that, too. I also see from trying the suggestion in Re^3: Code from perlboot not working as expected how to get a reference to the name, another point that was causing me confusion.

    Thanks and regards,

    John Davies