如何打印在另一個文件中定義的散列元素?如何打印在另一個文件中定義的散列元素?
file1.pl:
#!/usr/bin/perl
use strict;
use warnings;
our %hash =
("Quarter" , 25,
"Dime" , 10,
"Nickel" , 5);
file2.pl:
#!/usr/bin/perl
use strict;
use warnings;
require "file1.pl"
foreach (sort keys %hash){
print "$hash{$_}\n";
}
輸出:
Global symbol "%hash" requires explicit package name.
Global symbol "%hash" requires explicit package name.
請幫助
以供將來參考,請選擇您的代碼,然後按Ctrl-K或工具欄,以使你的代碼看起來正確的相應按鈕。 – ikegami 2013-03-27 07:30:13
(忽略我的投票關閉。我在關閉投票提到的職位已經插入了一個錯誤,因爲昨天他們的回答。) – ikegami 2013-03-27 07:37:33
http://stackoverflow.com/questions/4543934/how-to-share-export-a- global-variable-between-two-different-perl-scripts這個問題看起來類似於你所需要的。 – 2013-03-27 08:28:36