Seems only a few operators away from fully-fledged obfuscation, but it works, no? That's the annoying part. The other annoying part is how well it works.sub foo { return shift()->{foo}; }
Ideally, which is a euphemism for "in that place where all is well and good, but you can't get there from here", the named parameter method would be the fastest. Unfortunately, this is just not the case. with_inline_shift() is always the fastest, regardless of the number of parameters passed. In fact, it is about 30% faster with one parameter, and at least 10% faster when loaded with 1000 parameters.package Foo; sub with_shift { my $self = shift; return $self->{foo}; } sub with_inline_shift { return shift()->{foo}; } sub with_index { return $_[0]->{foo}; } sub with_list { my ($self) = @_; return $self->{foo}; }
In reply to Shift versus Sanity by tadman
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |