Consider:
use strict; use warnings; my $obj = bless {}; # As function do_something (); # As method $obj->do_something (); sub do_something { my ($self) = @_; if ($self && 'main' eq ref $self) { print "Called as method\n"; } else { print "Called as function\n"; } }
Prints:
Called as function Called as method
In reply to Re^3: What's the better Perl style? Define parameters or not?
by GrandFather
in thread What's the better Perl style? Define parameters or not?
by pureHeart
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |