in reply to skipping unwanted list items
> What would be the official or best practice to skip a variable in a list?
$ perldoc -f undef
...
my ($x, $y, undef, $z) = foo(); # Ignore third value returned
$ perldoc perldata
...
The list 1,,3 is a concatenation of two lists, 1, and 3, the first of which ends with that optional comma. 1,,3 is (1,),(3) is 1,3 (And similarly for 1,,,3 is (1,),(,),3 is 1,3 and so on.) Not that we'd advise you to use this obfuscation.
...
you may assign to undef in a list. This is useful for throwing away some of the return values of a function:
($dev, $ino, undef, undef, $uid, $gid) = stat($file);
As of Perl 5.22, you can also use (undef)x2 instead of undef, undef
undef assignment is official, commas are mostly ignored inside a list.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: skipping unwanted list items (How to find documentation)
by LanX (Saint) on May 10, 2026 at 12:29 UTC | |
|
Re^2: skipping unwanted list items
by harangzsolt33 (Curate) on May 10, 2026 at 12:44 UTC |