in reply to Handling Mac, Unix, Win/DOS newlines at readtime...
But since it's HTML data that you're working with, line breaks are only meaningful as such within <pre> ... </pre> -- which leads to at least three points that might be interesting for your situation:
- original data may have strange variations in the placement of line breaks, though this does not affect browser behavior;
- you can often "revise" the distribution of line breaks without any noticeable effect on browser behavior;
- the previous two points do not apply in certain portions of some HTML data (i.e. within <pre> elements).
If all you're doing is taking html data that is already "okay" and replicating it with some particular wrapping around it, your suggested code will be fine.
If your process involves any sort of filtering, enhancement or other modification of the content, then you will be much better off looking through the various HTML modules (especially HTML::Parser or HTML::TokeParser) to read the input properly. I frankly don't know how these will handle the subtler details of input from different systems. At worst, you may need to keep something like the code you suggested when handling the contents of <pre> blocks.
update: it sounds like you're producing all your output for just one system (the one running the perl script), which means you want to eliminate the variations in line-break characters. But if you had to keep the line-breaks as-is, so that the results could be read back nicely on the particular system that created each original, you'd want to modify your code just a little:
$file=''; open(IN,"<$filename") || die "$file can't be opened: $!"; { local $/=undef; $file=<IN>; } ($\) = (/(\r\n|\r|\n)/); # make output rec-separator same as input @lines=split /[\r\n]+/, $file; foreach $line (@lines) { # do some processing here }