1

我想批量存储 perl 的返回值。我该如何做到这一点?

Batch Code:
FOR /F "delims=" %%I IN ('perl.exe c:\TestProp1noRefCases.pl 859') DO set lineCase=%%I 
echo !lineCase! ::Nothing is outputted

Perl Code:
use strict;
use warnings;
sub main1;

my $arg1 =shift;
main1($arg1);
exit;
sub main1
{
            #Returns 1,2,3 Depending on testNum passed
            my @gp1= (829,845,851,859,864,867);
            my @gp2= (861,863,865);
            # my @gp4= (826-828,830-839,843-844,847-850,852-854,860-862,883);
    # my @gp3= (877-882,884);
            my $val1=1;
            my $val2=2;
            my $val3=3;
            my $val4=4;

            if((grep /^$arg1$/,@gp1) || ($arg1 >=822 && $arg1<=824))
            {     
                            # print "$val1\n";
                            return $val1;

            } elsif ((grep /^$arg1$/,@gp2) || ($arg1>=855 && $arg1<=858))
            {
            #print "$val2\n";
                            return $val2;
            } elsif (($arg1==884) || ($arg1>=877 && $arg1<=882))
            {
            #print "$val3\n";
                            return $val3;
            } else
            {
                #print "$val4\n";
                            return $val4;

            }

}
4

2 回答 2

1

您没有退出返回值。

代替

main1($arg1);
exit;

尝试:

my $result = main1($arg1);
exit $result;

或者:

exit main1($arg1);

然后%ERRORLEVEL%在您的批次中进行检查。

perl.exe c:\TestProp1noRefCases.pl 859
set lineCase=%ERRORLEVEL%

编辑:注意,这只适用于小的无符号整数,就像$val1..$val4你的例子一样。

于 2012-07-05T22:02:39.287 回答
1

您永远不会真正打印要捕获的值。改变

main1($arg1);

print main1($arg1);
于 2012-07-06T00:24:06.690 回答