Re: Search and replace for @
by japhy (Canon) on Jul 16, 2001 at 19:46 UTC
|
Your worries are ill-founded. And to the people that replied to this post, about interpolation and what-not, re-read his comment: the string is populated from a database query.
Had he written $x = "foo@bar", he'd have been warned by Perl. But that's not the case.
In addition, because the @ is in a string, there's no fear of it being read by Perl as an array, unless he evaluates the variable. All in all, he doesn't need to do jack to the string. In fact, adding a backslash will probably cause a mailing client to break.
_____________________________________________________
Jeff japhy Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??; | [reply] |
Re: Search and replace for @
by MZSanford (Curate) on Jul 16, 2001 at 19:26 UTC
|
$string =~ s/@/\\@/g;
But, i dont think perl will have a problem with $string because it is only a problem during string declaration.
OH, a sarcasm detector, that’s really useful | [reply] [d/l] [select] |
|
|
Also, when you populate $string, make sure you use single quotes so @foo is not interpreted as an array variable
$string = 'foo@foo.com';
$string =~ s/\@/\\@/g;
| [reply] [d/l] |
|
|
That's a very important point; unless you explicitly type into your code the email address, you don't need to escape the @ symbol. So populating $string from a database would need no extra work (and trying to do what you do may screw up the system later by introducing an unneeded backslash).
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
| [reply] |
Re: Search and replace for @
by suaveant (Parson) on Jul 16, 2001 at 19:30 UTC
|
| [reply] |
(jeffa) Re: Search and replace for @
by jeffa (Bishop) on Jul 16, 2001 at 19:28 UTC
|
s/@/\/@/g;
But the real problem lies in how you declare $string,
that is, the @ sign must be escaped if you use double
quotes:
$string = "foo\@bar.com";
# or better yet:
$string = 'foo@bar.com';
UPDATE:
_NOW_ i see the comment that says populated by DB query,
sheesh!
Jeff
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
| [reply] [d/l] [select] |
Re: Search and replace for @
by agoth (Chaplain) on Jul 16, 2001 at 19:31 UTC
|
Why not do some research?
Search this site for 'replacing', there are loads of hits.
Look in any perl books, they will have the answers....
| [reply] |
|
|
Thank you for your tactful RTFM reply.
...
I did search the site. I know how to do
this normally. I spcifically could not
figure out the combination for the "@" character.
Also, a search for "replace" on the site yielded
nothing.
A search for "search and replace" did not
yield my answer.
:)
| [reply] |
|
|
Fair enough, the post gave me the impression you hadn't bothered, sometimes varying the search to i.e replacing helps
| [reply] |