Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: modifying the search pattern of a file.

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


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://22349]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2025-02-07 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (95 votes). Check out past polls.