Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Answer: Can I read a line from a socket without the socket sending \n?

by mikeock (Hermit)
on Nov 04, 2005 at 15:56 UTC ( #505749=categorized answer: print w/replies, xml ) Need Help??

Q&A > network programming > Can I read a line from a socket without the socket sending \n? - Answer contributed by mikeock

I use a socket connection in a subroutine that closes after I send a command. The easiest way that I have found to read the text back is using the shutdown ($socket_name, 1). You can then run a

while(<$socket_name>){ print $_; }
to return whatever the prompt/responce is.

Again, for each command that I send, I create a new socket connection send the command and disconnect/kill the socket.

Also once the while loop is in place, you can use a regex to take what you want out, like the prompt, since it is making a new connection everytime.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2016-10-01 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (574 votes). Check out past polls.