in reply to Have trouble implementing a shell-alike script
Here we are reading with one kind of a \n (the capture of the ls command on Unix) and desiring to write with another kind of \n (the socket write). Oh, yes both Windows and Network line termination is the same (CRLF). Unix line termination is just LF. Perl considers LF and CRLF the same for reading in line mode.
I suggest this ...
At the moment, the Unix machine that I test with is down. However, the above code is in theory correct- check it out yourself! On read, \n means LF or CRLF. When Perl writes to Windows, a \n is CRLF. When Perl writes to a network socket, a \n is CRLF. I think the compiler can also figure out what to do with: join("/n", @captured_output);my @captured_output = split(/\n/,$ls_captured_line); ...then... foreach (@captured_output) { print socket "$_\n"; }
My point is that Perl can read lines terminated either way (\n meaning either just LF or CRLF). And further when Perl writes a \n, it will emit a LF or a CRLF depending upon what it is writing to. As weird as it sounds, Windows and Network \n is different than Unix \n.
|
|---|