[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Reading PC files



At 09.54 -0400 1998.07.23, William B. Birkett wrote:
>Is there a way to configure MacPerl to handle PC files?

Well, are you processing the whole file at once, or a line at a time, or what?

Note that these are put int separate blocks so the value of $/ is reset
when the block ends.

1.  whole file at once in a scalar

  {
    local($/) = undef;  # set input record separator to CRLF
    $file = join '', <FILE>;
    $file =~ s/\015\012/\n/g;
  }

2.  whole file at once in an array

  {
    local($/) = "\015\012";  # set input record separator to CRLF
    foreach (<FILE>) {
      chomp;
      push(@file, $_);
    }
  }

3.  line-by-line

  {
    local($/) = "\015\012";  # set input record separator to CRLF
    foreach (<FILE>) {
      chomp;
      do_something($_);
    }
  }

Hope this helps,

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch