in reply to avoiding overwriting variables in an inherited class
Now your 'JOKE' attribute is in a lexical variable, and not accessable outside of the lexical scope. So, it would not clash with whatever Email::Simple is using, nor will it clash with anything a subclass of FunnyEmail would be doing.package FunnyEmail; use base Email::Simple; use Hash::Util::FieldHash 'fieldhash'; ### Add this fieldhash my %JOKE; ### Add this sub new{ my $class = shift; my $text = shift; # assume this gets passed my $self=Email::Simple->new($text); $JOKE{$self} = undef; ### Change this bless $self,$class; return $self; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: avoiding overwriting variables in an inherited class
by whatnext156 (Initiate) on May 03, 2012 at 18:06 UTC | |
by JavaFan (Canon) on May 04, 2012 at 11:56 UTC |