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
In reply to Re: Modules Returning Values?
by Zaxo
in thread Modules Returning Values?
by Spidy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |