in reply to modifying a line in a file with some restrictions

I'm unsure why modifying $_ doesn't change the file

Still unsure why? :^).


Examine what is said, not who speaks.

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

  • Comment on Re: modifying a line in a file with some restrictions

Replies are listed 'Best First'.
Re^2: modifying a line in a file with some restrictions
by Aristotle (Chancellor) on Jan 14, 2003 at 09:00 UTC
    attempting to slurp the entire file ($/="")
    No, he's reading it in paragraph mode. See perlvar. Update: That is, of course, he would be reading it in paragraph mode if he had opened it for reading.
    Replacing everything in the file (if the file ends with a newline)
    No, he is only replacing the first line of the paragraph.

    Makeshifts last the longest.

      Good point about the paragraph mode, but he's not reading anything from a file opened write-only.

      However, if he was reading a paragraph, it wouldn't be the first line of the paragraph he would be replacing.

      The text replace would be the last line of the paragraph plus the two or more newlines that delimited the paragraph. Somehow I doubt that this was his intention, but the point is mute until he manages to read something in.

      Seems we both need to read perlop, and possibly perlre as well ....


      Examine what is said, not who speaks.

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

        The text replace would be the last line of the paragraph plus the two or more newlines that delimited the paragraph.
        Good catch about the (one!) newline, but I'm puzzled at how you arrive at other the conclusion. He is using /m which doesn't make the dot match newlines.
        $ perl -le'(join "\n", qw(foo bar baz)) =~ /(.*\n)/m && print $1' foo $ # note the embedded newline
        Yes, perlre is a good suggestion. ;-)

        Makeshifts last the longest.