hi fella monks, i'm having trouble on modifying the searched pattern found from a file. for example i have search this pattern in an html file.  <% INCLUDE file1.txt %> and this is located somewhere in the middle of the html file. how will i be able to replace this searched pattern with something like  <% INCLUDE file2.txt %> here's a someple of my code... now don't blame me i'm a newbie.
$template = "index.txt"; $counter = "counter.txt"; $pos = 0; $found = 0; $num = 0; open (F1, "+>$template"); @idxlines = <F1>; close F1; foreach $lines (@idxlines) { if ($lines =~ /<% INCLUDE file2.txt %>/) { $found = 1; last; } $pos++; } open (F1, "+<$template"); open (CT, "$counter"); $num = <CT>; close CT; if ($num == 2) { $num = "1" } else { $num++ } open(CT, ">$counter"); print CT $num; close CT; $idxlines[$pos] = "<% INCLUDE file$num.txt %>"; print F1 $idxlines[$pos]; close F1;
i'm using the counter file to increment the file(num).txt. i don't know if i'm doing it right... please help me. thanks in advance.

In reply to modifying the search pattern of a file. by damian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.