这个涉及到perl包了吧
只能写代码给你看了,细节可能需要自己去查资料。
1、建立一个文件,用于存储你的哈希表,名为MyHashTb.pm,里面的代码为:
#!usr/bin/perl -w
use strict;
package MyHashTb;
sub new
{
my $class = shift @_;
my $ref = {};
bless $ref,$class;
return;
}
sub set
{
my $class = shift @_;
$class -> {"key1"} = "value1";
$class -> {"key2"} = "value2";
...
$class -> {"keyN"} = "valueN";
}
sub get
{
my ($class,$key) = @_;
return $class -> {$key};
}
1;
#以package开头必须以1结尾
2、将MyHashTb.pm这个文件放到perl存放模块的目录下,之后其他.pl的perl程序可以通过以下代码调用它:
#!usr/bin/perl -w
use strict;
use MyHashTb;
my $key1 = "key1";
my $key2 = "key2";
my $hash_tb = MyHashTb -> new();
$hash_tb -> set();
my $value1 = $hash_tb -> get($key1);
my $value2 = $hash_tb -> get($key2);