in reply to mac win and unix EOL chars, $/ question

first of all, how can you be checking for the line ending of each line in a loop that relies on the value of that line ending to break input up line-by-line? if you want to do this, you can't use <> until you've determined what the value of $/. my advice is don't use it. just read the data with read and break up the lines manually with split.

there is probably already a module that does the following, but this code reads in a file in chunks of a specified number of bytes and splits the input into an array containing lines and line endings in the order they are found in the file. so, passing the array returned to print should print out the exact, original file contents.

$CHUNK_SIZE = 4096; open FILE, $file or die "$!\r\n"; while (read FILE, $chunk, $CHUNK_SIZE) { # split the chunk into a list of parts, keeping # the line endings in the array @parts = split /(\r\n?|\n)/, $chunk; if (defined $partial) { $part[0] = $partial . $part[0]; undef $partial; } # if the last part is not a line ending, then # the line could potentially be continued in # the following chunk if ($parts[-1] !~ /^\r\n?|\n$/) { $partial = pop @parts; } push @lines_and_endings, @parts; } push @lines_and_endings, $partial if defined $partial; close FILE; print @lines_and_endings; @just_lines = grep { ! /^\r\n?|\n$/ } @lines_and_endings;