在一个文件中声明一个哈希表并在 Perl 中的另一个文件中使用它 [英] declaring a hash table in one file and using it in another in Perl
本文介绍了在一个文件中声明一个哈希表并在 Perl 中的另一个文件中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在一个文件中创建一个哈希表并在另一个文件中使用.原因是该表是我的数据库"并且将被更改,我希望它与所有其他数据文件一起使用,而不是与脚本文件一起使用.
I need to create a hash table in one file and use in in another. The reason for it is that that the table is my "database" and will be changed, and I want it to seat with all the other data files, and not with the script files.
如何在脚本中使用表格?
How can I use the table in my script?
推荐答案
在全局或包变量中定义哈希表.然后使用 do
命令将定义加载到另一个脚本中:
Define your hashtable in a global or package variable. Then use the do
command to load the definition into another script:
datafiles/database.def
---------------------------
package ProjectData;
our %DATA = ('abc' => 'def', 'ghi' => 'jkl', ...);
scripts/myscript.pl
------------------------
use strict;
do 'datafiles/database.def';
... do something with %ProjectData::DATA ...
这篇关于在一个文件中声明一个哈希表并在 Perl 中的另一个文件中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文