I do it all the time. No big deal. Of course, this being perl, there are a few more ways to do it...
# implicit return. sub to_xml { shift->to_html(@_) } # get rid of shifting - only if there is no one deriving off # this object, and to_html is in the same package. sub to_xml { to_html(@_) } # what are we passing in @_ for? sub to_xml { &to_html } # ah, heck, this whole thing is just an alias anyway. *to_xml = \&to_html;
Note how once we get rid of the shift, anyone who overrides to_html won't see their overridden version when the call is to_xml. So the behaviour is a little different in that case. I don't think any other use of to_xml would be different between all these ways.
Update: If the overriding difference doesn't bother you, I do think the last one is the fastest as it avoids an extra subroutine call. It's also something that many people don't see too often, so you may avoid it for that reason, too.
In reply to Re: One line accessor method style.
by Tanktalus
in thread One line accessor method style.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |