Would this not be a case where File::Find would be appropriate to find those files you need? Perhaps something along the lines of:

# # UNTESTED CODE # use File::Find; # If desired, change following to absolute path(s) to search my @directories = ('.'); find(\&search_and_replace, @directories); sub search_and_replace { # Item from search is a file -f && # Item's full name ends with '.shtml' $File::Find::name =~ m/\.shtml$/ && # Rename file so there is a backup rename($File::Find::name, $File::Find::name . '.bak'); # Read from original (now .bak), writing to target open(INF, $File::Find::name . '.bak') or die('Input: ', $!, "\n"); open(OUTF, '>' . $File::Find::name) or die('Output: ', $!, "\n"); { # Localize $_ to prevent potential problems with call local($_); # Loop thru file, doing replacements while ($line = <INF>) { $line =~ s!(href="?)main\.page\?page=!$1/id=!g; print(OUTF $line); } } close(OUTF); close(INF); }

Hope that the idea above at least helps.

Update: Added comments for clarification.


In reply to Re: Massive File Editing by atcroft
in thread Massive File Editing by Kage

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.