是否可以在 Linux 机器上共享由另一个 Perl 脚本创建的哈希值?
./hash_script.pl # Creates a hash after parsing a file
# Takes several minutes and hash consumes 4Gb of memory
./script1.pl # Reads hash
./script2.pl # Reads hash
我想创建一次哈希并多次使用它,无论何时运行 script1.pl
和 script2.pl
。
最佳答案
如果您的 hash_script 脚本将其散列转储到某个文件中(使用 Data::Dumper 或其他方式),您可以使用 do
在后续脚本中加载该散列。
在脚本 1/脚本 2 中:
our %sharedhash; #whatever name the hash has in the dumped file
do 'hash_dump_file.txt' or die "Couldn't read hash: $@";
print $sharedhash{stuff};
关于perl - 跨 Perl 脚本共享哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20080989/