[Israel.pm] how to read a file to a Hash?

Gaal Yahas gaal at forum2.org
Sun Jul 11 00:00:45 PDT 2004

On Sat, Jul 10, 2004 at 10:21:53PM +0200, liat wrote:
>    nstore \%hash, 'file';
>    my $hashref = retrieve('file');

People have commented on this, but haven't necessarily made clear
what's wrong with it. What you're doing here is storing a hash to a
local file, then retrieving it into a new hash(ref). In effect, you have
made an expensive clone of %hash. What you want is to use Storable to
serialize %hash onto the socket, instead of the file; the *other side*
of the socket reads the serialized data from the network and
deserializes it.

Also, are you using the low-level socket funcitons for the sake of your
excercise, or because those are the only ones you know? Take a look at
the IO::Socket documentation if the latter case is true, it should make
your task easier.

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list