Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Variable Name Mistery. Who calls?

by ikegami (Patriarch)
on Oct 25, 2006 at 16:32 UTC ( [id://580620]=note: print w/replies, xml ) Need Help??


in reply to Variable Name Mistery. Who calls?

Objects encapsulate data. This can include their name/id.

package Foo; sub new { my ($class, $id) = @_; my $self = { id => $id }; return bless $self, $class; } sub method { my ($self) = @_; ... if (...something went wrong...) { warn("$self->{id} rotted into a pile of mush\n"); } ... }
use Foo; my $one = Foo->new('one'); my $second = Foo->new('two');

( If what you want to do is possible, it'll be hard, fragile and error prone. That's why I suggested this alternative. )

Replies are listed 'Best First'.
Re^2: Variable Name Mistery. Who calls?
by Fletch (Bishop) on Oct 25, 2006 at 16:46 UTC

    You could also modify this to save information from caller and store off the filename and line number where the constructor was called from if a more meaningful name isn't provided (of course I don't know offhand how that'd behave with subclasses . . .).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found