in reply to Modules Returning Values?
Beware, you can't bless just any old scalar value: it must be a reference you bless. Also, return is not really necessary unless you are returning from somewhere in the middle of the function's code.
Is your new() a class constructor method? If so, you should consider writing it as,
to be called by, my $cs = CheckStuff->new(); That avoids the surprises you will get by having $bar a package global. You would find that with two CheckStuff objects around, their values would both be the same; whatever was set last. It also makes the constructor inheritable, so that if CheckStuff::Rigid has CheckStuff as a base class, my $csr = CheckStuff::Rigid->new(); always returns the right sort of object.packsge CheckStuff; sub new { my $class = shift; my $bar = 2; bless \$bar, $class; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Modules Returning Values?
by jfroebe (Parson) on Aug 31, 2004 at 21:49 UTC |