in reply to [Solved] Avoiding repeated undefs
> It seems to me to be inelegant to repeat undef
No, is not. Compiler does not bother with elegance ;)
Anyway I suspect you cannot avoid them repeated: you are are in left side of an assignement, and inside a my declaration: no array (well you mean list?) can be there.
PS
An eventual list as second (or whatever..) element in the assignement will slurp everything
perl -e "$str = 'a b c d e f g';@arr=(1,2,3,4,5); ($key, @arr, $val) = + split(/\s+/, $str); print qq($key $val\n@arr\n)" a b c d e f g # even if the array is presized: perl -e "$str = 'a b c d e f g';$#arr=4; ($key, @arr, $val) = split(/\ +s+/, $str); print qq($key $val\n@arr\n)" a b c d e f g
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Avoiding repeated undefs
by hippo (Archbishop) on Feb 26, 2019 at 10:08 UTC | |
by rsFalse (Chaplain) on Feb 28, 2019 at 00:15 UTC | |
by choroba (Cardinal) on Feb 28, 2019 at 06:37 UTC |