in reply to Re: Problem with String replace in file
in thread Problem with String replace in file

if I use

s/\|\|/|\\N|/g;

it replaces || with ||. The \N seems to be an invisible newline character, and I want it to just be '\N'.
  • Comment on Re^2: Problem with String replace in file

Replies are listed 'Best First'.
Re^3: Problem with String replace in file
by meraxes (Friar) on Oct 22, 2007 at 17:36 UTC

    I suspect your problem is that you are writing back to the filehandle IN when you (presumably) only opened it for read.

    open( IN, '<', $filename ); # input open( OUT, '>', 'newfilename.txt' ); # output while ( <IN> ) { s/\|\|/|\\N|/g; print OUT; } close IN; close OUT;
    --
    meraxes
      This was correct, thank you. || is replaced by |\N| throughtout newfilename.txt.
Re^3: Problem with String replace in file
by ikegami (Patriarch) on Oct 22, 2007 at 17:40 UTC

    \n will result in a newline.
    \N will result in a syntax error.
    \\N will give \N.

    If you're not getting \N from \\N, there's something you haven't showed us.

    Update: meraxes caught the problem.