[tpm] Is there a three-way version of...

John Macdonald john at perlwolf.com
Mon Jun 1 10:09:20 PDT 2009


On Sat, May 30, 2009 at 05:20:56PM -0400, Shaun Fryer wrote:
> > i generally don't like using shift on @_ and prefer to assign it.
> 
> True for complex stuff. My feeling is that when it's a very short
> method (one liner), like a simple accessor, shift is faster (from
> benchmarks I've seen) and not unclear/unmaintainable. For instance...
> 
>     sub foo { return shift()->{foo} = shift if @_ }
> 
> ...seems quite reasonable to me. YMMV
> 
> > never duplicate deep access code. use a temp var with the lower level
> > reference and it will be clearer and if you do need multiple uses, faster.
> 
> Seems reasonable.
> 
> > ...in the bizarre case of someone setting $] which changes the index origin,
> > @array will stay the same but $#array will change.
> 
> Good point.
> 
> Thanks for the input.

I tend to use $self = shift in methods - that leaves @_
looking the same way os the list of arguments specified in
the method call.

I'll also use $var = shift if there is only one arg and I don't
expect there to ever be a second arg.  (I won't convert to this
form, though, if a refactoring reduces the arg count down to 1.)


More information about the toronto-pm mailing list