barryghall has asked for the wisdom of the Perl Monks concerning the following question:

I need to determine the kind of line ending (Windows, Unix of Mac) used in each of a set of input files and based on the kind of line endings convert the line endings of the file to Unix.

Assume that the array @Files holds the paths to the files of interest

pseudocode would be:

For each file $F in @Files

if $F is a text file:

my LE = getEndings($F) #$LE is the endings type, Windows, Unix or Mac

if ($LE eq 'Windows' or $LE eq 'Mac') {change $F to Unix line endings}

getEndings is a subroutine that determines the line endings

The files of interest can be huge so I can't expect to slurp the entire file contents into memory. Instead, to convert a Windows or Mac file I expect to read the file line by line, chomp each line, then writing that line with usual Unix line endings to a file named temp.txt. After closing temp.txt I would remove the original file and rename temp.text to the original file name.

I have not been able to figure out how to write a getEndings subroutine that works with all three kinds of line endings. Any suggestion will be much appreciated<\p>

The notion to read files line by line and write lines to temp.txt should work for files with Windows endings but with Mac line ending the lines would not be read correctly. Any ideas?