我正在開發一個小的Perl腳本來自動執行一些服務器任務,當我在Windows計算機上測試它時一切正常,但是當我將它上載到Linux服務器時,腳本返回多個:在Windows和Linux下使用未初始化的值更改
Use of uninitialized value $line in chomp at CreateEntity.pl line 52, <HANDLE> line 5.
Use of uninitialized value $line in string ne at CreateEntity.pl line 52, <HANDLE> line 5.
Use of uninitialized value $string in substitution (s///) at CreateEntity.pl line 67, <HANDLE>
Use of uninitialized value $string in substitution (s///) at CreateEntity.pl line 68, <HANDLE>
Use of uninitialized value $string in substitution (s///) at CreateEntity.pl line 67, <HANDLE>
Use of uninitialized value $string in substitution (s///) at CreateEntity.pl line 68, <HANDLE>
這裏是代碼本身:
#!/usr/bin/env perl
# This fils SHOULD go in the root of Symfony... put it anywhere else AT YOUR OWN RISK !!!
use warnings;
# Declare the subroutines
sub trim;
if(!defined $ARGV[0])
{
die("No FilePath Specified!\n");
}
my $entityFile = $ARGV[0];
open(HANDLE, $entityFile) or die("The file could not be open!");
my $entityCmd = "php app/console doctrine:generate:entity --entity=\"rapliqBundle:";
my $entityName = "";
chomp(my $line = (<HANDLE>));
$line = trim($line);
while($line ne "END")
{
if(trim($line) ~~ "NAME:")
{
chomp($line = (<HANDLE>));
$entityName = trim($line);
$entityCmd = $entityCmd . $entityName;
$entityCmd = $entityCmd . "\" --fields=\"";
}
elsif(trim($line) ~~ "FIELDS:")
{
chomp($line = (<HANDLE>));
my @data = split('=', $line);
foreach my $val (@data)
{
$val = trim($val);
if($val ~~ lc "string")
{
$entityCmd = $entityCmd . $val . "(255) ";
}
else
{
$entityCmd = $entityCmd . $val . ":";
}
}
}
52: chomp($line = (<HANDLE>));
}
close(HANDLE);
$entityCmd = $entityCmd . "\"";
#print $entityCmd;
system($entityCmd);
system("php app/console doctrine:generate:entities rapliqBundle:" . $entityName);
system("php app/console doctrine:schema:update --force");
sub trim
{
my $string = $_[0];
67:$string =~ s/^\s+//;
68:$string =~ s/\s+$//;
return $string;
}
感謝您的任何想法或意見:)
編輯:我把行號爲關注在代碼行前面。
我已經添加到我的答案。 – ikegami 2013-02-19 21:48:08