unix shell脚本中的perl timegm()错误

时间:2016-03-23 08:07:52

标签: perl

我正在尝试在unix脚本中运行perl脚本。但是在执行它时我得到一个错误。没有timegm()perl函数它工作正常。这是代码和错误消息。

#!/ bin中/ KSH

    echo "I M IN KSH"
    i=10
    echo "value of i in ksh is $i"
    perl << _MYCODE_

    print "I M IN PERL\n";
    use Time::Local;

    my \$i = $i;    
    print "Value of i in perl $i\n";    
    $time_epoo = timegm(13,06,22,29,2,2016-1900);     

    print "$time_epoo"

    _MYCODE_   

    echo "BACK IN KSH"

------------------------OUTPUT WITH ERROR--------------
I M IN KSH
value of i in ksh is 10
syntax error at - line 7, near "="
Execution of - aborted due to compilation errors.
BACK IN KSH
-------------------------------------------------------

1 个答案:

答案 0 :(得分:2)

使用-e标志来执行perl。然后使用参数方法将shell变量传递给perl脚本。然后使用$ARGV[0]

处理perl中的值
echo "I M IN KSH"
i=10
echo "value of i in ksh is $i"
perl -e '

print "I M IN PERL\n";
use Time::Local;

my $i = $ARGV[0];
print "Value of i in perl $i\n";
$time_epoo = timegm(13,06,22,29,2,2016-1900);

print "$time_epoo"

'   $i

echo "BACK IN KSH"