Remy Guo wrote:
> hi all,
> i have a text processing script that can work with a file but cannot work
> with another file that has the same content.
> as i compared the 2 files, i found the file that cannot work has a "^M" at
> the end of each line. what is this? is this what made it not work?
> by the way, i'm under unix.
> thanks....

That will be your editor's representation of control-M, ASCII carriage return or
"\x0D". Windows files uses a CR LF pair as the record terminator.

Because a regex pattern of /\s/ matches both CR and LF (and FF) as well as tab
and space, a loop like this

  while (<DATA>) {
    s/\s+$//;
      :
  }

will do the same as a chomp, but will also remove trailing tabs and spaces,
which is usually what is wanted.

More properly, and especially if trailing whitespace is significant, you could
change the input record separator by writing

  {
    local $/ = "\x0D\x0A";

    while (<DATA>) {
      chomp;
        :
    }
  }

HTH,

Rob

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


Reply via email to