One important thing to remember is that sweeping s/this/that/ functions can have unintended results. For example john.foo@there.com will become john.bar@here.com which may not be the desired result. I highly recommend doing a SEARCH first, printing lines where matches are found (along with the intended changes), and only after an eyeball scan to make sure we are not going to get bitten do the REPLACE. You really need to identify what will change as in big data sets you may be forgetting something rather critical. Worse it may take weeks to discover the error by which time other changes often make resorting to backup (you did make a BACKUP didn't you?) impractical. This advice is based on having been bitten before. Consider:
while(<DATA>){
my $orig = $_;
if ( s/foo\@there\.com/bar\@here\.com/ ) {
print "< $orig> $_\n";
}
}
__DATA__
foo@there.com
john.foo@there.com
foo@there.com.au
<a href="mailto:foo@there.com">Mr Foo</a>
Which generates:
< foo@there.com
> bar@here.com
< john.foo@there.com
> john.bar@here.com
< foo@there.com.au
> bar@here.com.au
< <a href="mailto:foo@there.com">Mr Foo</a>
> <a href="mailto:bar@here.com">Mr Foo</a>
Often it can be as simple as adding a boundary condition \b but in this case it does not work (carefully chosen examples :-). I suggest this sort of approach
s{([a-zA-Z_\.]+\@[a-zA-Zz\.\-]+)}
{$1 eq $old ? $new : $1}ge
In this approach we find email address like tokens, see if they are what we want to change..... Note this *still* leaves you with the issue of Mr Foo now linking to presumably Mr Bar's address. This may or may not be an issue. The initial scan phase let's you *see* if it is an issue.....
As an aside having email addresses on you web pages is like asking for spam. In this day and age it is worth considering an alernative approach. I would suggest linking to an upload form CGI. The user clicks on an email link like <a href="/cgi-bin/mailer?to=sales>Contact Sales</a> and your CGI provides the email form. This has several advantages. First people can email you without needing a functional email client, it protects your email addresses, and it abstracts the link from sales to sales@mydomain.com into a single config location, removing the prolem you currently have forever. NMS formmail is a reasonably secure canned solution for the back end. An alternative is to use Javascript - there are several techniques.
|