Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Real Basic Perl OOP Question

by Codon (Friar)
on Jun 21, 2005 at 22:16 UTC ( [id://468833]=note: print w/replies, xml ) Need Help??


in reply to Real Basic Perl OOP Question

This is a very basic error. bless() returns a blessed reference; it does not operate on the referent. In otherwords, when you do this:
bless $objref, $class
you are not getting the benefits of the bless(). Try this instead:
my $self = bless $objref, $class; return $self;
Ivan Heffner
Sr. Software Engineer, DAS Lead
WhitePages.com, Inc.

Replies are listed 'Best First'.
Re^2: Real Basic Perl OOP Question
by fishbot_v2 (Chaplain) on Jun 21, 2005 at 23:08 UTC

    That is not correct - bless alters its first argument in-place:

    use Data::Dumper; my ( $ref1, $ref2 ) = ( {}, {} ); my $ref3 = bless $ref1, 'Foo'; # capturing results bless $ref2, 'Foo'; # in void context print Dumper $ref3; print Dumper $ref2; __END__ # results identical: $VAR1 = bless( {}, 'Foo' ); $VAR1 = bless( {}, 'Foo' );

    bless returns the reference as a convenience, however it certainly operates on the reference. (It doesn't alter that which is referenced {the "referent"?}... but he's not doing that, and that isn't what you are demonstrating either.)

      This is awesome. I love this site.

      Thanks, man.
      My "this is awesome" comment was meant to be a reply to you...
Re^2: Real Basic Perl OOP Question
by o2bwise (Scribe) on Jun 21, 2005 at 23:42 UTC
    Hi Codon,

    Thank you. Though I am confused.

    Based on a recommendation by Zaxo (where I posted this before and didn't realize it was available), I changed:

    my $name2 = Message->name( $message_obj );

    to

    my $name2 = $message_obj->name( );

    and it worked! :-)

    Tony

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://468833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-18 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found