我正在尝试执行以下脚本,但没有获得所需的输出。似乎它仍在保留旧值并继续连接它。
./test.pl -v v10,v11,v12
实际结果 => 'v10','v11','v10','v12','v10','v11','v10'
预期结果 => 'v10','v11','v12'
你能帮忙解决这个问题吗?
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my ($versionFlag,$finalVersionList);
sub validateInputAndFilter
{
my ($passedVersionList) = @_;
$finalVersionList ="";
my @versionList = split(",",$passedVersionList);
foreach my $ver (@versionList)
{
if($ver =~ m/^v[0-9][0-9]$/)
{
$finalVersionList .= "'$ver',$finalVersionList";
}
else
{
print "\nWARNING: Passed version *** $ver *** is NOT in expected format...skipping...\n";
}
}
$finalVersionList =~ s/\,$//;
print "\n\nfinalVersionList => $finalVersionList\n\n";
}
GetOptions('v|version=s' => \$versionFlag) || die "Please pass version list separated by comma";
if(defined $versionFlag)
{
&validateInputAndFilter("$versionFlag");
}
else
{
die "Please pass version list separated by comma";
}
exit 0;