Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Reading froma dynamic file handle

by mikeock (Hermit)
on Nov 22, 2005 at 16:11 UTC ( #510841=note: print w/replies, xml ) Need Help??


in reply to Reading froma dynamic file handle

I always loop through a socket connection to get the data that I want. my code would be as follows:

Code is untested

#!/user/bin/perl -w use strict; use IO::Socket::INET; sub sock_connection{ my $sockname = new IO::Socket::INET(PeerAddr => "putAddrHere", PeerPort => "Port", Proto => "tcp") or die "cannot +connect to host: $!"; print $sockname "@_" # Puts data passed to sub shutdown($sockname, 1); while(<$sockname>){ # place regex to remove prompt message # Display msgs using print $_; } undef $sockname }

if the code is called in a subroutine, like the above, you can then call the subroutine to loop through the code that you want to send to the socket.

sock_connection("my command here")

Hope this helps?!

Edit:Added the undef to clear the socket connection when done.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://510841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2023-03-21 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (59 votes). Check out past polls.

    Notices?