update: tachyon makes a good point in his reply to this reply. If you think your data set may contain such a catch, make sure you follow his advice :)

I really shouldn't have written the whole thing for you, but whatever, I'm in a good and helpful mood. This could most likely be done in less code using the 'find' command in combination with perl's inline editting, but I don't know enough about such things. Note that I copped out by simply slurping each file into memory one at a time. You could rescript it to do line-by-line editting if you wish, though you'd have to add usage of a temporary file.

#!perl -w use strict; use File::Find; find( \&handle_it, '/foo/bar' ); sub handle_it { return unless m!\.html\z!; my $name = $File::Find::name; open( my $fh, '+<', $name ) or (warn("open on $name failed: $!\n") and return); my $content = do { local $/; <$fh> }; $content =~ s!foo\@there\.com!bar\@here\.us!g; seek($fh, 0, 0) or die("seek on $name failed: $!\n"); truncate($fh, 0) or die("truncate on $name failed: $!\n"); print $fh $content; close($fh) or die("close on $name failed: $!\n"); }

In reply to Re: multi-file search-and-replace by saskaqueer
in thread multi-file search-and-replace by aplonis

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.