#tcpserver.pl #!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; use Storable qw(nfreeze); $| = 1; my ( $socket, $clientsocket ); my ( $peeraddress, $peerport ); my $data; my $line; my $inputfile = "list.txt"; my %names = (); my $reftohash; open my $fh, '<', $inputfile or die "can't open file: $!"; # read file while ( $line = <$fh> ) { chomp $line; $names{$line} = 1; } close $fh or die "can't close file: $!"; #set hash reference $reftohash = \%names; $socket = new IO::Socket::INET( LocalHost => 'localhost', LocalPort => '5000', Proto => 'tcp', Listen => 5, Reuse => 1 ) or die "ERROR in Socket Creation : $!\n"; #while(1) { $clientsocket = $socket->accept(); print $clientsocket nfreeze($reftohash); #} $socket->close();