sub undeff { @_[0..-1] = (); };
-1 is the last index ... much easier to read. (And faster, too.)
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
| [reply] [d/l] |
Yes, that works in most other languages.
In ruby, arr[0..-1] returns all elements
of the array (and is an lvalue too).
In python, arr[0:-1] is all but the last
element, arr[0:] or arr[:] is
all elements. In octave, you don't have negative
array indexes, but you have avec(:) for all
of the vector, but also no special notation for all the
elements starting the n'th (like arr[n:] in
python). In mathematica, you have arr[[All]]
for all elements of the array, but also no starting
slice notation. (These are only a few languages of course.)
Anyway, you can write 0..$#_ or even
0..@_ as the index, or avoid indexing completely
and say sub undeff { undef $_ for @_ }.
| [reply] [d/l] [select] |
But it does not work.
0..-1 is zero elements.
| [reply] |