我知道如何在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