[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-win32-users
Subject: Can't use $\ to force line termination to 0x0a
From: "L. Neil Johnson" <neiljohn () xmission ! com>
Date: 2005-02-24 6:51:15
Message-ID: 01C51A02.9070DE60.neiljohn () xmission ! com
[Download RAW message or body]
An MS-DOS batch file launches a PERL script which calculates input
specifications for a filter-design program written in FORTRAN running under
cygwin's shell for MS-DOS. The specifications are written by PERL to many
text-files which are read by the UNIX-based program. Therein lies the
problem. PERL for Win32 writes the line terminators as CRLF (0x0d0a), and
the UNIX-based program blows up reading the "unexpected character" CR. What
we want to do is write LF (0x0a) as the text-file termination character.
Simple, no?
PerFunc documentation for binmode() says: "See the $/ and $\ variables in
the perlvar manpage for how to manually set your input and output
line-termination sequences." The PerlVar documentation for $\ says:
"Ordinarily the print operator simply prints out its arguments as is, with
no trailing newline or other end-of-record string added. To get behavior
more like awk, set this variable as you would set awk's ORS variable to
specify what is printed at the end of the print. (Mnemonic: you set $\
instead of adding ``\n'' at the end of the print..."
So we did what it what it said (I hope). LineTermTest.plx tests different
combinations of $\ and \n. No configuration produces the desired LF
termination.
# 'print' Line Termination Test
# Use "od -Ad -txz <fname" to display hex dump of output
# 1. What is the default setting of $\?
# ($\ is a scalar that contains a string.)
$BS = $\;
if (defined ($BS)) {print ("$BS")} # Can't use $\ before double-quote
else {print "\$\\ undefined on entry.\n"}
# Output: "$\ undefined on entry."
# 2. String with default $\ but no \n
print ("A");
# Output: 0x41 [no termination]
# 3. String with default $\ and \n
print ("B\n");
# Output: 0x420d0a [B followed by CRLF]
# 4. String with $\="\x0a", no \n
# Backslash escape to insert hex value in double-quoted string
$\ = "\x0a";
print ("C");
# Output: 0x430d0a [C followed by CRLF]
# 5. String with $\="\x0a" and \n
print ("D\n");
# Output: 0x440d0a [D followed by CRLF]
# 6. String with embedded LF, no \n
print ("E\x0a");
# Output: 0x450d0a [E followed by CRLF]
Is $\ being overridden? It appears that even though $\="\x0a" may terminate
print lines with LF, this character is replaced by CRLF at a lower layer
before output to the file.
Does $\ work as advertised under W32? Sorry for using the -v option :-)
Thank you, Neil
Environment: W98SE, ActiveState PERL for MSWin32-x86-multi-thread, build
631, 1/2/2002.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic