忽略列表赋值中的元素的最佳方法是什么?

Wes*_*Wes 5 perl

我使用列表分配将制表符分隔的值分配给不同的变量,如下所示:

perl -E '(my $first, my $second, my $third) = split(/\t/, qq[a\tb\tc]); say $first; say $second; say $third;'
a
b
c
Run Code Online (Sandbox Code Playgroud)

要忽略某个值,我可以将其分配给虚拟变量:

perl -E '(my $first, my $dummy, my $third) = split(/\t/, qq[a\tb\tc]); say $first; say $third;'
a
c
Run Code Online (Sandbox Code Playgroud)

我不喜欢有未使用的变量。还有其他方法吗?

too*_*lic 6

您可以使用undef

use warnings;
use strict;
use feature 'say';

(my $first, undef, my $third) = split(/\t/, qq[a\tb\tc]);
say $first; 
say $third;
Run Code Online (Sandbox Code Playgroud)

输出:

a
c
Run Code Online (Sandbox Code Playgroud)