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 . . .).