in reply to Referencing an object's value

you
  • donīt use strict;
  • donīt use the two argument form of bless();
  • donīt get a reference to self in your method
  • use the bareword self where you mean $self in new()

  • That is what causes the wrong behavior of your class.
    Compare to this code (that works as intended):
    use strict; my $p = Foo->new(); $p->bkg_img("whatever"); $p->print_html; package Foo; sub new { my $class = shift; my $self = {}; $self->{BKG_IMAGE} = "image"; bless($self, $class); return $self; } sub bkg_img { my $self = shift; $self->{BKG_IMAGE} = $_[0]; } sub print_html { my $self = shift; print <<"HTML"; $self->{BKG_IMAGE} HTML }

    holli, regexed monk

    Replies are listed 'Best First'.
    A reply falls below the community's threshold of quality. You may see it by logging in.