我正在使用列表分配将制表符分隔的值分配给不同的变量,如下所示:
perl -E '(my $first, my $second, my $third) = split(/\t/, qq[a\tb\tc]); say $first; say $second; say $third;'
a
b
c
要忽略某个值,我可以将其分配给虚拟变量:
perl -E '(my $first, my $dummy, my $third) = split(/\t/, qq[a\tb\tc]); say $first; say $third;'
a
c
我不喜欢有未使用的变量。还有其他方法吗?
您可以使用undef:
use warnings;
use strict;
use feature 'say';
(my $first, undef, my $third) = split(/\t/, qq[a\tb\tc]);
say $first;
say $third;
输出:
a
c