Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

learning oo

by Anonymous Monk
on Aug 16, 2002 at 14:55 UTC ( [id://190659]=perlquestion: print w/replies, xml ) Need Help??

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

Can anyone tell me why the method getName() returns "Shape=HASH(0x81073ec)->getName()"? Thanks Monks!



# Shape.pm package Shape; sub new { my $class = shift; my $self = { COLOR => "clear", LNGTH => "0", WIDTH => "0", NAME => "blank", @_, }; return bless $self, $class; } sub getName { my $self = shift; return $self->{NAME}; } 1; # in lego.pl use Shape; $circle = Shape->new( COLOR => "red", LNGTH => "2", WIDTH => "2", NAME => "barney" ); print "The color of \$circle is: $circle->getName()\n"; exit(0);

Replies are listed 'Best First'.
Re: learning oo
by cephas (Pilgrim) on Aug 16, 2002 at 14:58 UTC
    Your object reference is getting interpolated in the double quoted string. Try:

    print 'The color of $circle is: ', $circle->getName(),"\n";


    cephas
Re: learning oo
by Zaxo (Archbishop) on Aug 16, 2002 at 15:13 UTC

    Calls to subs are not interpolated. cephas' solution is correct, or else either

    print "The color of \$circle is: @{[$circle->getName()]}\n";
    or
    print "The color of \$circle is: ${\$circle->getName()}\n";
    depending on whether you want list or scalar context.

    After Compline,
    Zaxo

some OO (ahem) references, ;-)
by BorgCopyeditor (Friar) on Aug 16, 2002 at 15:18 UTC

    If the usual docs aren't enough for you to see your problem (perlref, perltoot, perlobj, perlbot), you might read the slower, more detailed discussion that's offered as a sample chapter from Object Oriented Perl.

    Update: Oops! Forgot merlyn's perlboot. You know that feeling you get when you spot a movie star at the grocery store? I'm having that feeling right now.

    BCE
    --Your punctuation skills are insufficient!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found