[Israel.pm] a hash question
Shlomi Fish
shlomif at iglu.org.il
Mon Feb 2 11:50:27 PST 2004
On Monday 02 February 2004 21:07, Eitan Schuler wrote:
> Shlomi,
> Thank you for your quick help,
> DB_File deals with hashes very well, and easy to use.
> Just in case if anybody intersted:
>
> use DB_File;
> my $X = tie %myhash, "DB_File", "C:\\temp\\hehe.dat",$DB_HASH or
> die "can't open file";
>
> #pushing values
> $X->put("a",3);
> $X->put("b",4);
> $X->put("c",7);
>
Actually, you can substitute these calls with:
<<<
$myhash{"a"} = 3;
$myhash{"b"} = 4;
$myhash{"c"} = 7;
>>>
> #checking if exists
> print "a exists in myhash\n" if $myhash{"a"};
>
That should be:
print "a exists in myhash\n" if exists($myhash{"a"});
After all $myhash{a} could exist and be equal to "" or 0.
> #Getting a value
> $X->get("c",$value);
Or:
<<<
$value = $myhash{"c"};
>>>
Moreover, keys(), each() and friends also work on such hashes.
Not that I have anything against your code. After all, there's more than one
way to do it. But I think using the tied variable maps directly to the hash
analogy.
Regards,
Shlomi Fish
---------------------------------------------------------------------
Shlomi Fish shlomif at iglu.org.il
Homepage: http://t2.technion.ac.il/~shlomif/
I don't believe in fairies. Oops! A fairy died.
I don't believe in fairies. Oops! Another fairy died.
More information about the Perl
mailing list