I consider my example to pass $#a as an argument an extremely common case
While I disagree about the commonness of passing $#a, there are options if it is deemed to be too slow.
$#a as an arg is an lvalue. Users can pass 0+$#a if they want the extra speed of an rvalue.
$#a as an arg is an rvalue. Users can use ${ \$#a } if they want an lvalue.
$#a as an arg is a delayed lvalue. I don't know if the mechanism can be extended to $#a, but hash element lookups are like this:
$ perl -le'\$h{k}; print exists($h{k})?1:0' 1 $ perl -le'sub{ $x=$_[0] }->($h{k}); print exists($h{k})?1:0' 0 $ perl -le'sub{ $_[0]=$x }->($h{k}); print exists($h{k})?1:0' 1 $ perl -le'sub{ $x=$_[0] }->(@h{k}); print exists($h{k})?1:0' 1 $ perl -le'sub{ $_[0]=$x }->(@h{k}); print exists($h{k})?1:0' 1
In reply to Re^9: Does @{ } copy arrays?
by ikegami
in thread Does @{ } copy arrays?
by tford
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |