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

liat rin_liat at netvision.net.il
Sat Jul 10 13:21:53 PDT 2004

first of all thank you all for your help, i'm working on a project for my
studies, alone without a guide
and your help and directions are very useful and needed!!
actually i'm looking for a perl expert for a privat lessons (by pay of
course)  , so if anyone can and want to, plz let me know

about the project, those are the modules of the server and client sides

the server side===>>
    use strict;
    use Socket;
    use Carp;
    use Storable qw(nstore retrieve nstore_fd fd_retrieve);

    my $port = 2345||shift  ;
    ($port) = $port =~ /^(\d+)$/  or die "invalid port";

    #creating the socket
    my $proto = getprotobyname('tcp');
    socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";

    #the 'bind' func'
    my $sin= sockaddr_in($port, INADDR_ANY) ;  #the 'sin' will insert
    bind(Server,$sin )|| die "bind: $!";       # into the bind func'

    #the 'listen' func'
    listen(Server,SOMAXCONN)  || die "listen: $!";

    print "Server accepting clients!!!\n";
    my $paddr;

    #the 'accept' func'
	$paddr=accept(Client,Server) || die $!;

   if (open(FILE,"url"))
   my $line = <FILE> ;
      while ($line)
      send(Client,$line,0,)or die "send() failed: $!";
         $line= <FILE> ;

     my %hash = (
		"netvision" => {
			"adsl" => {
				"uname" => 'name',
				"upass" => 'pass',
			} ,
			"cable" => {
				"uname" => 'name',
				"upass" => 'pass',
			} ,
		"zahav" => {
			"adsl" => {
				"uname" => 'name',
				"upass" => 'pass',
			} ,
			"cable" => {
				"uname" => 'name',
				"upass" => 'pass',
			} ,
			"dialup" => {
				"uname" => 'name',
				"upass" => 'pass',
			} ,

   nstore \%hash, 'file';
   my $hashref = retrieve('file');
   send(Client,$hashref,0,)or die "send() failed: $!";

the client side===>

use strict;
    use Socket;
    my ($remote,$port, $iaddr, $paddr, $proto);
	my $line;
    my @all_lines;
    my %hashref;

    $remote  = shift || '';
    $port    = 2345||shift ;  # random port
    if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
    die "No port" unless $port;

    $proto   = getprotobyname('tcp');
    socket(SOCK, PF_INET, SOCK_STREAM, $proto)  || die "socket: $!";

    $iaddr   = inet_aton($remote) || die "no host: $remote";
    $paddr   = sockaddr_in($port, $iaddr); #the paddr will insert
                                           # into the connect func'
	connect(SOCK, $paddr)    || die "connect: $!";

    my $hashref;

    recv(SOCK, $hashref,300,0)   or die "recv() failed: $!";

   my $isp;
   my %family;
   my $roles;
   my $person;
   my $kind;
   my $user;
   my $pass;
  while ( ($isp, $roles) = each %$hashref ) { ##need to write %$hashref in
order to get the
                                              ##hash of the reference the
'retrieve' returns
    print "$isp: ";
    while ( ($kind, $person) = each %$roles ) {
        print "$kind=> ";
         while ( ($user, $pass) = each %$person ) {
        print "$user=$pass ";
    print "\n";

    close (SOCK)            || die "close: $!";

it's not working of course becuase the sending of the "hashref" if not fits
to the client side
and as you see the client need to get the hash and printing it (kind of

liat koski

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il]On Behalf Of
Gabor Szabo
Sent: Saturday, July 10, 2004 7:20 PM
To: Perl in Israel
Subject: RE: [Israel.pm] how to read a file to a Hash?

plese show relevant code examples so we can point to where to fix things.

It is a lot easire to help and it is also good because the examples remain
in the archive for the help of future generations....


Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list