in reply to modifying the search pattern of a file.
open(FILE, $file) or die $!; @lines = <FILE>; close FILE; for ($i = 0; $i <= $#lines; $i++) { if ($lines[$i] =~ /<% INCLUDE file(\d+)\.txt %>/) { $num = $1; # UPDATE: # ok, the next line (original) is wrong, see replies # $num = $num == 1 ? 1 : 2; # We have to write it this way: $num = $num == 1 ? 2 : 1; $lines[$i] =~ s/<% INCLUDE file(\d+)\.txt %>/<% INCLUDE file$num\. +txt %>/; } else { next; } open(FILE, ">$file") or die $!; print FILE @lines; close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: modifying the search pattern of a file.
by dempa (Friar) on Jul 13, 2000 at 15:27 UTC | |
by turnstep (Parson) on Jul 13, 2000 at 22:15 UTC | |
by le (Friar) on Jul 13, 2000 at 15:35 UTC |