[Israel.pm] a hash question

Eitan Schuler Eitan.schuler at exlibris.co.il
Mon Feb 2 12:44:34 PST 2004


Yes, you are right.
Anyway, I will tomorrow try to make some performance test on unix to see how
much time it takes to make massive 'push' and 'existance check' for a couple
of gigas of data.

Thank you
Eitan

-----Original Message-----
From: Shlomi Fish [mailto:shlomif at iglu.org.il]
Sent: Monday, February 02, 2004 9:50 PM
To: Perl in Israel
Subject: Re: [Israel.pm] a hash question


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.

_______________________________________________
Perl mailing list
Perl at perl.org.il
http://www.perl.org.il/mailman/listinfo/perl

YAPC::Israel::2004
http://www.perl.org.il/YAPC/2004/



More information about the Perl mailing list