我正在开发一个小的 Perl 脚本来自动化一些服务器任务,当我在我的 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;
}
感谢您的任何想法或评论:)
编辑:我将相关行的行号放在代码行的前面。