in reply to Re^3: Abstract Factory
in thread Abstract Factory

package Greet::Repeat; sub new { my $class = shift; my $self = { greeting => shift, repeat => shift, }; return bless $self, $class; } sub greet { my $self = shift; print ($self->{greeting} x $self->{repeat}); } 1;
doesn't understand the role of shift and bless, completely; where we have greeting and repeat are being shift.

Replies are listed 'Best First'.
Re^5: Abstract Factory
by Anonymous Monk on Oct 06, 2005 at 06:05 UTC
    I had same problem, Read : bless and shift
    package Bug; sub print_me { my ($self) = shift; # The @_ array now stores the arguments passed to &Bug::print_me # The rest of &print_me uses the data referred to by $self # and the explicit arguments (still in @_) } or, better still: package Bug; sub print_me { my ($self, @args) = @_; # The @args array now stores the arguments passed to &Bug::print_m +e # The rest of &print_me uses the data referred to by $self # and the explicit arguments (now in @args) }
    $nextbug = { id => "00001", type => "fatal", descr => "application does not compile", }; To turn that anonymous hash into an object of class Bug you write: bless $nextbug, "Bug";