Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Re: modifying the search pattern of a file.

by le (Friar)
on Jul 13, 2000 at 10:39 UTC ( [id://22349]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 11:27 UTC
    I don't want to be picky, but shouldn't:

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

    be:

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

    ?

      Of course, sorry... I was in a hurry.
      Or perhaps:
      $num--; $num||= 2; or $num=$num%2 ? 2 : 1;

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://22349]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.