|No such thing as a small change|
Is there a variable in which Perl stores the native file delimiter for the platform on which your script is running?by jira0004 (Monk)
|on Dec 23, 2005 at 00:11 UTC||Need Help??|
jira0004 has asked for the wisdom of the Perl Monks concerning the following question:
On Windows the line terminator is the two charcter sequence \x0d \x0a. On UNIX the line terminator is the single character \x0a.
If you are processing a file and you do not use binmode on the file handle, then Perl automatically uses and recognizes the native line terminator for your platform \x0d \x0a on Windows, \x0a on UNIX. Thus, $x = <FILE_IN>; will result in the last character sequence in $x being \x0d \x0a on a Windows platform and \x0 on a UNIX platform. Likewise, print FILE_OUT "Hello.\n"; will result in H e l l o . \x0d \x0a being written to the output file on Windows and H e l l o . \x0a on UNIX.
In my Perl script I allow the user to specify which line terminator to use on the command-line so that the user can get either a file with Windows line terminators or a file winth UNIX line terminators regardless of what platform the user is running on. I am doing this because we are generating data files and I need the right line terminator in the data file and the right line terminator in this specific case is not necessarily the platform native one.
I want to default to the platform native line terminator if the user does not specify a line terminator. However, I am using binmode on my file handle so on Windows Perl won't automatically translate \n to \x0d \x0a.
What I want to know is, does Perl store the native line terminator character in a special global variable? If so which one?
Can some one tell me how I can find out dynamically at run time what the native line terminator is for the platform on which my script is running?