At 3:15 pm +0000 22/12/05, James Harvard wrote:
I'm trying to detect a file's line endings (\r\n for DOS, \r for Mac
and \n for Unix as I'm sure y'all know).
Is there any easy way to do this?
At 10:45 am +0800 21/11/02, Peter N Lewis wrote:
At 13:22 +0000 20/11/02, John Delacour wrote:
if (/\015\012/) {
$/ = "\015\012" ;
} elsif (/\015/) {
$/ = "\015" ;
} else {
$/ = "\012" ;
}
You can do this with one regular expression which will pick up the
first line ending:
$/ = /(\015\012|\015|\012)/ ? $1: "\n";
Note that because Perl picks the first match location, and after
that picks the first of an or "|" set, it will find the first
location, and will find the \015\012 if it is there in preference to
the \015 by itself.
Enjoy,
Peter.