我知道如何在Perl中使用从一个包到另一个包的变量。我正尝试在另一个Perl脚本test2.pl
中使用在test1.pl
中声明的全局变量。我正在使用require
加载perl文件。如何在另一个Perl脚本中使用变量?
#!usr/bin/perl #test1.pl
use strict;
use warnings;
out $db_name; #global variable to be used in another script
fun();
sub fun
{
$db_name = 'xxyy';
}
#!usr/bin/perl #test2.pl
require 'test1.pl'; #require is used to include the perl script like we use "use" for importing packages
my $database = $db_name; #global variable from previous script
use strict;
use warnings;
testing();
sub testing
{
print "$database\n";
}
它不是'out',其'our'。 – serenesat
[Perl:如何在需要的脚本中提供需要脚本的变量](http:// stackoverflow。com/questions/7542120/perl-how-to-make-variables-from-require-script-available-required-script) – serenesat
其实这个问题没有'warnings'。 – simbabque