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

Update
In short

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

    How to find documentation

    To check this yourself you can either use perldoc ° on the commandline like demonstrated, or use the excellent full text search in perldoc.perl.org (expand menu)

    NB: you can restrict your search to your beloved 5.8.X miniperl

    https://perldoc.perl.org/5.8.0 (adjust subversion)

    Last but not least you can use my keyword search for X<tags>

    Perldoc Keyword Search (update3)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    °) see also monastery markup [doc://perldoc], [doc://undef], [doc://perldata]

Re^2: skipping unwanted list items
by harangzsolt33 (Curate) on May 10, 2026 at 12:44 UTC
    Oh, okay. Thank you!