in reply to Modifying File Contents

ramthen--

Since davido and johngg solved the problem, I won't bother with that. Especially as davido's suggestion was much shorter than I was going to write... 8^)

But as I've done basically the same task for a client, I thought I'd add one thing: You may want to consider putting guard strings before and after your string, and modifying the regex to require the guard strings. Appropriate guard string selection can help you avoid changing more things than you intended to in your program.

This may not be a problem in your case, but in our case, we didn't want to inadvertently change data strings along with our serial number.

--roboticus

Replies are listed 'Best First'.
Re^2: Modifying File Contents
by bart (Canon) on Mar 19, 2006 at 11:22 UTC
    Another safeguard would be to specify that the substitution may happen only once per file. Assuming there is at least one appearance of a version string in the file, and most likely, it's near the very top of the file, that should work and protect you reasonably well.

    I'm thinking that the easiest way to achieve that is to simply slurp the whole file, and process it with a single s///. Source files are usually short enough to not pose any problems. According to perlrun you can use the -0777 switch to slurp the whole file (that's a zero, not a capital O, BTW. I always make that mistake.)