jacques has asked for the wisdom of the Perl Monks concerning the following question:
Later in the *same* package I want to get the value of $self->{BKG_IMG} in another sub and print it to STDOUT. For example (this is bad code):sub new { my $self = {}; $self->{BKG_IMAGE} = "image"; bless($self); return $self; } sub bkg_img { my $self = shift; $self->{BKG_IMAGE} = $_[0]; }
All the code is in the same package (not main). Here's the kicker: Within main, a user can set the value $self->{BKG_IMAGE} by doing:sub print_html { print <<"HTML"; $self->{BKG_IMAGE} HTML } print_html();
Whether or not, the value is set by the user before it's printed, I need to reference the current value of $self->{BKG_IMAGE} in that aforementioned sub (print_html). And it has to be the correct value! Note that the value is first set in new(). That's my problem and my question. Thanks.$p = new MyPackage; $p->bkg_img("whatever");
----------
This is my real question. Thank you to those who replied to this one.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Referencing an object's value
by Tanktalus (Canon) on Jan 21, 2005 at 22:45 UTC | |
|
Re: Referencing an object's value
by Errto (Vicar) on Jan 21, 2005 at 23:15 UTC | |
|
Re: Referencing an object's value
by holli (Abbot) on Jan 21, 2005 at 23:04 UTC | |
|