|Don't ask to ask, just ask|
Re^3: What's the point of this 'overload' idiom?by stevieb (Canon)
|on Dec 07, 2022 at 07:33 UTC ( #11148643=note: print w/replies, xml )||Need Help??|
Is a lazy man's way of saying:
In other words, it's a quick way of not declaring the 'self' variable. I do it a different way if I have a one line sub:
...the following is equivalent:
When a Perl method receives its parameters, the first one is always the calling object. shift or $_ is the same thing; the object itself. If a method is more than one line, I prefer to collect the parameter as self (eg. my ($self) = @_;). That's not always the case.
Note that shift->thing; only works once... once you've shifted the object off the stack, you can't call shift again. In these cases, $_ is better, but if you have to use $_ more than once, you're far better off for self-documenting purposes to use my ($self) = @_;.
In Section Seekers of Perl Wisdom