1 2 if ($#ARGV < 1) { 3 print "Usage: version.pl VER FILE {FILE, FILE}\n"; 4 exit; 5 } 6 7 $V=$ARGV[0]; 8 print "VER:'${V}'\r\n"; 9 shift(@ARGV); 10 11 sub replace () { 12 my $filename = $_[0]; 13 14 if(-s $filename) { 15 print "Processing [" . $filename . "]\r\n"; 16 17 my $original = "$filename.original"; 18 19 rename($filename, $original); 20 open(OUT, ">$filename"); 21 open(IN, "$original"); 22 23 my $hitCount=0; 24 while(<IN>) { 25 if($hitCount == 0 && /<version>.*<\/version>/) { 26 s/<version>.*<\/version>/<version>${V}<\/version>/; 27 $hitCount++; 28 } 29 print OUT; 30 } 31 close(IN); 32 close(OUT); 33 unlink($original); 34 } else { 35 print "File [" . $filename . "] does not exist\r\n" 36 } 37 } 38 39 foreach $ARG (@ARGV) { 40 do replace($ARG); 41 } 42 43 44 45