in reply to Re^8: Does @{ } copy arrays?
in thread Does @{ } copy arrays?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Does @{ } copy arrays?
by BrowserUk (Patriarch) on Oct 23, 2009 at 22:22 UTC | |
by ikegami (Patriarch) on Oct 23, 2009 at 22:56 UTC | |
|
Re^10: Does @{ } copy arrays?
by LanX (Saint) on Oct 23, 2009 at 20:33 UTC | |
by ikegami (Patriarch) on Oct 23, 2009 at 20:45 UTC |