Good day Monks,
I have a problem that is bewildering me and I am sure its due to my lack of knowledge. I have built a small LISTENER using IO::Socket in which I pass a string from the client which represents a GroupName. I appear to be doing what I want until the time I try and use the variable in my DBI function that will extract members of the Group and then recursively extract all sub-groups until only the non-groups exist and I pass them back from the function and want to return to the socket client which made the initial request. The getGrpMembers() works correctly when I use the snippet of code outside the socket code but not when embedded within...any help in trying to understand my BREAKDOWN would be greatly appreciated...
Thanks,
Danny
#!/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"; } } } }

In reply to IO::Socket and passed variables to functions by onegative

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.