How can I update the same line in several different files?
I have a dozen or so Perl files with this line:
my $version = "<span class=\"foottext\"><em>version 0.11</em></span>";
This is line 7 of each perl file. The element I need to batc开发者_JAVA技巧h-modify is "X.XX" -- the version number.
What is the most elegant script I can run from the shell (in Perl) to open each file, change the version number on line 7, and then write the file?
A quick Google search reveals that the following one-liner should help:
perl -pi -w -e 's/version 0\.11/version 0.12/g;' *.pl
On a more general note, you should avoid code duplication and move that line into one (single) library file that is called by your dozen other files.
精彩评论