in reply to Re^4: modifying a line in a file with some restrictions
in thread modifying a line in a file with some restrictions

Usual way, I tried it:). I've never had occasion to make use of paragraph mode, hence my mistaking it for slurp mode, so I tried it out to see what the effect was and the code below was my test suite.

Test code

#! perl -sw use strict; local $/=""; while (<DATA>) { s/.*\n$/fred/m; print; } __DATA__ The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog

output

C:\test>226772 The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog fred The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog fred The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog fred The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog fred The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog The quick brown fox jumps over the lazy dogThe quick brown fox jumps o +ver the lazy dog fred C:\test>

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re^6: modifying a line in a file with some restrictions
by Aristotle (Chancellor) on Jan 14, 2003 at 10:26 UTC
    Arrgh! Duh. I missed the $. Of course \n$ requires two consecutive newlines to match, which is only true at the end of the paragraph (and guaranteed to be true there due to the nature of paragraph mode), and since the . doesn't match newlines, the whole expression can only match the last line.

    Makeshifts last the longest.