in reply to Shift versus Sanity
Although speed was and is definately not my motivation, more the elgance of the notation. Although I am pleased to hear that it is in fact more efficient. :-)sub my_method { my ($self,$data)=shift->self_obj; }
Other than that in general I agree with tye pretty much on this one. I often use shift as it is easier to reorganize during development, easier to document and much easier to provide defaults for.
Of late I've found myself using $_[$x] a lot as well, primarily as I have been working on a few things where either of the other two techniques can cause problems as they copy their values and not alias to them.
Oh yes, when I first started learning perl I reviewed a bunch of the standard modules and corresponded with GSAR about why he (more or less) exclusively used the my $x=shift; idiom (at least in Data::Dumper). Turned out there is/was a bug in an older version of perl that the shift technique worked around.
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.
|
---|