Jan Eden wrote:
Jan Eden wrote on 10.12.2004:

I use the following to read in lines from an uploaded file:

  my $fh = $q->upload('input_file');
  while (<$fh>) { push @urls, $_; }

It works fine when the file has UNIX or DOS linebreaks, but it fails
with Macintosh linebreaks. What is the best method to read in a
Macintosh file (other than splitting the file manually after reading
it into one scalar)?

Sorry for generating unnecessary traffic, I found the solution myself:

    while (<$fh>) {
        my @line = split /[\r\n]+/; $_;
        push @urls, @line;
    }

This works with any line-ending - if there are \n linebreaks, the split
does nothing, if I have an [\r\n] combination, the split will find a \r
at the end of $_, but nothing behind it, if I only have \r, the whole
file will be one line to be split at once.

You should probably read the "Newlines" section of the "Writing portable Perl" document.


perldoc perlport


John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to