On Jul 26, 2006, at 21:59, Steve Pittman wrote:

I am using activestate on a windows box ...the files I am parsing are
Unix files...I tried this so far...

open ( IN, "<$_[0]" )||die "Can't open DAT source file: $tempFile
$!\n";
        while (<IN>){s/\r/\n/g;@lines = <IN>;}#
        close (IN);
        
        foreach $line (@lines)
        {

If the file has Unix conventions a line-oriented loop on Windows works out of the box:

  while (my $line = <$fh_of_unix_text_file>) {
      chomp $line;
      # ...
  }

The reason why this works is that no pair CRLF ever gets into $line on Windows working in text mode. That's because when reading the I/O layer substitutes them on the fly with simple LFs. The readline operator returns $/-separated chunks, and $/ is "\n" by default, which is precisely eq to LF on Windows. As you know, LF is the line separator on Unix.

If the file actually has CR conventions (as said in the subject) instead of Unix conventions (as said in the body), then just set $/ accordingly and use a regular line-oriented loop as well:

  {
      local $/ = "\015"; # tell readline to use CR
      while (my $line = <$fh_with_cr_convention>) {
          chomp $line;
          # ...
      }
  }

-- fxn




--
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