Video retrieval
Video retrieval

Reputation: 25

replacing CR LF in perl with "|"

Using Perl, I want to replace CRLF by | in the end of a line beginning with "ID".

So, to be more explicit: If a line begins with "ID", I replace CRLF in the end of this sentence by |.

This is what I have done:

    elsif ($line =~ /^ID:\n/) { print $outputFile $line."|"; }

I think that it is not good ..

Upvotes: 0

Views: 319

Answers (1)

Toto
Toto

Reputation: 91518

Depending on platform, \n has diffrent meanings. From perlport:

    LF  eq  \012  eq  \x0A  eq  \cJ  eq  chr(10)  eq  ASCII 10
    CR  eq  \015  eq  \x0D  eq  \cM  eq  chr(13)  eq  ASCII 13
             | Unix | DOS  | Mac  |
        ---------------------------
        \n   |  LF  |  LF  |  CR  |
        \r   |  CR  |  CR  |  LF  |
        \n * |  LF  | CRLF |  CR  |
        \r * |  CR  |  CR  |  LF  |
        ---------------------------
        * text-mode STDIO

You could do:

elsif ($line =~ /^(ID\b.*)\R/) { print $outputFile "$1|" }

\R stands for any kind of linebreak.

Upvotes: 2

Related Questions