Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling EOL char(s) in text file 1

Status
Not open for further replies.

dpestian

Programmer
Joined
Dec 30, 2002
Messages
1
Location
US
Is there a way to override the EOL char(s) that Perl uses as I write out lines to a text file? I use:

Code:
print TempFH "units: in\n";

but when I look in the file it has both the carriage return and newline characters in the file. I am running from a command prompt in Win2k but wanted to know if I can overwrite the default EOL.

-TIA
 
I'm pretty sure a \n is always a newline, and what that is depends on your system. In windows, it just happens to be cr/lf (0x0D/0x0A).

Perl uses an input record separator (not sure of the terminologoy) that is stored in $/ This value is what it breaks on when you $line = <FILE> and the value it removes from the end when you chomp $line. You could just dump a hex value. Say you wanted the *nix newline, you could say
Code:
print TempFH &quot;units: in\x0D&quot;;

Again, I'm pretty sure \n is system defined and the user cannot change that, but I've been wrong once or twice before in life. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
To change it you have to set two Perl variables, the Input Record Separator and the Output Record Separator.

$/ -- the IRS
$\ -- the ORS

dpestian, have a look in the perlvar documentation for the entry on &quot;The output record separator for the print operator&quot;. Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top