in reply to modifying the search pattern of a file.

This is pretty untested. It should switch between file1.txt and file2.txt.
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
    I don't want to be picky, but shouldn't:

    $num = $num == 1 ? 1 : 2;

    be:

    $num = $num == 1 ? 2 : 1;

    ?

      Or perhaps:
      $num--; $num||= 2; or $num=$num%2 ? 2 : 1;

      Shamefully, --$num||=2; is not allowed.

      Of course, sorry... I was in a hurry.