#!perl -w use strict; use IO::Socket; use IO::Select; # advantage: we know all the variables that are used # within this particular scope. my ( $server, $handles, $sessions ); $server = IO::Socket::INET->new( Listen => 1, LocalAddr => 'localhost:8000' ) or die "socket failed: $!"; $handles = IO::Select->new( $server ); # disadvantage: at first glance, we can't tell if this is # the first time we are assigning to $sessions. You'd have # to scroll up from this point to see if we've already # put data into $sessions. $sessions = {}; { my $socket; while ( $socket = $server->accept() ) { $sessions->{$socket} = { peerhost => $socket->peerhost() }; } } #### #!perl -w use strict; use IO::Socket; use IO::Select; my $server = IO::Socket::INET->new( Listen => 1, LocalAddr => 'localhost:8000' ) or die "socket failed: $!"; my $handles = IO::Select->new( $server ); # advantage: we know this is the first time $sessions # is being assigned to. Any '$sessions = ...' later in the # program are obviously replacing the contents of $session. my $sessions = {}; while ( my $socket = $server->accept() ) { $sessions->{$socket} = { peerhost => $socket->peerhost() }; }