onegative has asked for the wisdom of the Perl Monks concerning the following question:
#!/opt/app/telalert/perl5.8.8/bin/perl use DBI; use IO::Socket; use IO::Select; require "SOCK_DBI.pl"; #require "getDate.func"; # Create a socket to listen on. # my $listener = IO::Socket::INET->new( LocalPort => 8888, Listen => 5, Reuse => 1 ); die "Can't create socket for listening: $!" unless $listener; print "Listening for connections on port 8888\n"; my $readable = IO::Select->new; # Create a new IO::Select object $readable->add($listener); # Add the listener to it while(1){ # Get a list of sockets that are ready to talk to us. # my ($ready) = IO::Select->select($readable, undef, undef, unde +f); foreach my $s (@$ready) { # Is it a new connection? # if($s == $listener) { # Accept the connection and add it to our readable lis +t. # my $new_sock = $listener->accept; $readable->add($new_sock) if $new_sock; print $new_sock "HELO\r\n"; } else { # It's an established connection my $buf = <$s>; # Try to read a line # Was there anyone on the other end? # if( defined $buf ){ # If they said goodbye, close the socket. If n +ot, # echo what they said to us. # if ($buf =~ /goodbye/i) { print $s "TelAlert Query Exit\n"; $readable->remove($s); $s->close; } else { chomp($buf); &declareGlobalVariables; # DBI->trace(1,'/tmp/dbi.log'); $dbh = &getOracleLogin("$ORACLE_SID", "$OR +ACLE_USERID", "$ORACLE_PASSWORD"); $dbh->{LongReadLen} = 64000; push(@groups, $buf); # Place received Grou +pName ($buf) into groups array to use for recursive database query $scale = scalar(@groups); # Scalarize grou +ps array for while statement below while( $scale > 0 ){ $grp = shift(@groups); # Extract Group +Name and Remove from groups array # BREAKDOWN IS HERE the $grp variable +is WEIRD when printed and will not feed correctly into next function. +.. @members = &getGrpMembers($grp); foreach $member (@members){ if( $member =~ /Destination/ ){ ($device, $trash) = split(/~/, + $member); push(@dest, $device); } if( $member =~ /User/ ){ ($user, $trash) = split(/~/, $ +member); push(@dest, $user); } if( $member =~ /Group/ ){ ($mem, $trash) = split(/~/, $m +ember); push(@groups, $mem); } } $scale = scalar(@groups); } print $s "@dest\n"; &logoffOracle($dbh); } } else { # The client disconnected. $readable->remove($s); $s->close; print STDERR "Client Connection closed\n"; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket and passed variables to functions
by chromatic (Archbishop) on Dec 16, 2008 at 23:47 UTC | |
|
Re: IO::Socket and passed variables to functions
by gone2015 (Deacon) on Dec 16, 2008 at 23:56 UTC | |
|
Re: IO::Socket and passed variables to functions
by ig (Vicar) on Dec 17, 2008 at 00:34 UTC | |
by Anonymous Monk on Dec 17, 2008 at 01:54 UTC | |
by ig (Vicar) on Dec 17, 2008 at 03:26 UTC | |
by onegative (Scribe) on Dec 17, 2008 at 04:33 UTC | |
by almut (Canon) on Dec 17, 2008 at 02:34 UTC |