parsing email addresses

J

James

I have a form that saves e-mail addresses to file and then sends them an
email but to send the email it need to be in the form a\@b.c.d not (e-mail address removed)
how can I get it to add the \ in front of the @ because I tried using =~ /@/
but it doesn't work because it changes it from (e-mail address removed) to a.c.d without the
\ how can I fix this?

Thank You
 
P

Paul Lalli

James said:
I have a form that saves e-mail addresses to file and then sends them an
email but to send the email it need to be in the form a\@b.c.d not (e-mail address removed)

Why do you believe you need this? If you're using this data in a
program, only litteral @ characters need to be escaped, not @
characters that come from a datafile.
how can I get it to add the \ in front of the @ because I tried using =~ /@/
but it doesn't work

Of course it doesn't. You didn't try to change anything. /@/ is a
simple pattern match, not a substitute and replace.
because it changes it from (e-mail address removed) to a.c.d without the \

No it doesn't. It doesn't change anything to anything else.
how can I fix this?

Have you read the posting guidelines for this group? Please post a
short-but-complete script that illustrates your problem. That means
*actual* code that you're using.

Now, the answer to the question you actually posted - which I seriously
doubt is what you actually need - is the following:

s/@/\\@/;

However, if there is anything else in your pattern match after the @,
it is most likely that Perl will interpret the @ as the start of an
array variable, and that it would need to be escaped:

s/\@stuff/\\\@stuff/;

Once again, though, I most strongly ask why it is you think you need to
do this at all. I fail to believe (with the information you provided)
that any of this is actually necessary to accomplish your goal.

Paul Lalli
 
P

Paul Lalli

Abigail said:
James ([email protected]) wrote on MMMMCCCXXXIX September MCMXCIII in
<URL:-- I have a form that saves e-mail addresses to file and then sends them an
-- email but to send the email it need to be in the form a\@b.c.d not (e-mail address removed)
-- how can I get it to add the \ in front of the @ because I tried using =~ /@/
-- but it doesn't work because it changes it from (e-mail address removed) to a.c.d without the
-- \ how can I fix this?


$ sed -e 's/@/\\@/' file > file.$$ && mv file.$$ file

Any particular reason you'd recommend this over the equivalent Perl
one-liner? (at least, in this group)

perl -pi -e's/@/\\@/' file

Paul Lalli
 
J

Joe Smith

Abigail said:
Paul Lalli ([email protected]) wrote on MMMMCCCXXXIX September MCMXCIII in
<URL::: Abigail wrote:
::
:: > $ sed -e 's/@/\\@/' file > file.$$ && mv file.$$ file
::
:: Any particular reason you'd recommend this over the equivalent Perl
:: one-liner? (at least, in this group)
:: $ sed -e 's/@/\\@/' file > file.$$ && mv file.$$ file

Speed.

OK, I'll bite. How big does the input file have to be before the
speed of the sed version is noticeably faster than the perl version?
 
B

Brian Wakem

Joe said:
OK, I'll bite. How big does the input file have to be before the
speed of the sed version is noticeably faster than the perl version?


It'll take twice as long to type the sed version so it'll need to be much
faster to justify the programmer time.
 
B

Brian Wakem

Abigail said:
You must be a real slow typer then, if saving 25 keystrokes is measurable
programming time.



Abigail


You can type 25 characters in an immeasurably short period of time? You are
amazing!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top