in reply to Detect line endings with CGI.pm upload
If you are absolutely sure that they are text files, ... something like the following could be used to normalize everything to match your current system's line endings.
Assume the content of the file is in $file:
$file =~ s/(\x0d?\x0a|\x0d)/\n/smg;Now when you write the string to disk, the line endings will be consistent.
It's important to do the alternation in the correct order, otherwise you can get a surprising result. If you don't have to worry about old Macs, you can get away with:
$file =~ s/\x0d?\x0a/\n/smg;Make certain you don;t do this to non-text files, the results are not recoverable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Detect line endings with CGI.pm upload
by ikegami (Patriarch) on Dec 26, 2008 at 22:07 UTC | |
by gwadej (Chaplain) on Dec 26, 2008 at 23:06 UTC | |
by ikegami (Patriarch) on Dec 26, 2008 at 23:43 UTC | |
by gwadej (Chaplain) on Dec 28, 2008 at 20:55 UTC | |
by ikegami (Patriarch) on Dec 29, 2008 at 00:39 UTC | |
|
Re^2: Detect line endings with CGI.pm upload
by apu (Sexton) on Dec 28, 2008 at 10:58 UTC | |
by gwadej (Chaplain) on Dec 28, 2008 at 21:01 UTC |