I've been slamming my head against the same brick wall all afternoon, so I thought I'd ask for help.
I am attempting to write a TCP server in Perl. This server will listen on a port and accept incoming communications. The first line of the incoming request is read, some decisions are made, and then the rest of the request is read in. I need to get the entire rest of the request into one scalar character string, so I was doing this:
$clientRequest = "";
while (<CLIENT>) {
$clientRequest .= $_;
}
Obviously there is also an ending condition (it checks $_ against a preset "end of file" value).
This, when run, produced some extremely mangled strings. When I tried to print out $clientRequest doing something like this:
print "clientRequest is $clientRequest\n";
I would end up with something like
clientTextest is lastlinesentbyclient
What am I missing? Please tell me it's something obvious and make me feel stupid - at this point, that's the best thing I could hope for.
Thanks,
Jen
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.