in reply to Object Awareness

1. You're assigning to a method call at: my $self->pop = shift;. You don't want to do that (though it's in some cases possible to make it work). You want to assign to the internal property "pop" instead.

2. The "my" in that statement is throwing off the perl interpreter. my should only be used to introduce new variables. Object properties aren't new variables, so lose it.

Corrected example for pop():

sub pop{ my $self = shift; if (@_) { # test for next argument $self->{pop} = shift; # assign argument to "pop" value } return $self->{pop}; # return "pop" value }
Note that pop is also a built-in function, so overriding it in your packages may lead to confusion or worse.

Replies are listed 'Best First'.
Re^2: Object Awareness
by Anonymous Monk on Mar 10, 2008 at 01:20 UTC
    The OP should note also that if he or she had had the statement  use warnings; at the start of the DoStuff.pm file, it would have been apparent that  my $self ... in the statement  my $self->pop = shift; masked the lexical variable of the same name defined and initialized in the  my $self = shift; statement of the immediately preceding line.
Re^2: Object Awareness
by wcpyro (Novice) on Mar 10, 2008 at 05:54 UTC
    Thank you, and thanks for the note about pop and use warnings Works perfectly :>

      Just to amplify a little - you should always use strictures (use strict; use warnings) because they give you early warning about issues. Those issues may be as simple as a typo, or more subtle as in your case. Use strictures with every Perl program you write and take note of any errors or warnings that are produced.


      Perl is environmentally friendly - it saves trees

      Unfortunately, Perl somewhat goes back to the philosophy held by an early (and probably apocryphal) COBOL compiler which, when given a copy of Lincoln's Gettysburg Address as input, “compiled it.”

      The philosophy of “there's more than one way to do it” presupposes that the writer knew what he was doing and that your (the computer's) interpretation is, if not correct, at least plausible. This is not necessarily the case.

      So you just need to begin every Perl program-file with... "shebang ... use strict ... use warnings ..."