How to substitute "@" for "\@" in a string?

J

jbauza

I need to replace the '@' from an email address to read ' \ @ '.

I have tried the split, the index/substring and the substitute methods
to no avail.
Cannot get Perl to either split, find the index or do the substitution
of the "@".

Any hints/help would be appreciated.

Thanks in advanced,

Joanna
 
I

it_says_BALLS_on_your forehead

jbauza said:
I need to replace the '@' from an email address to read ' \ @ '.

I have tried the split, the index/substring and the substitute methods
to no avail.
Cannot get Perl to either split, find the index or do the substitution
of the "@".

my $string = '(e-mail address removed)'; # note the single quotes
print "old: $string\n";
$string =~ s/@/\\@/;
print "new: $string\n";
 
I

it_says_BALLS_on_your forehead

it_says_BALLS_on_your forehead said:
my $string = '(e-mail address removed)'; # note the single quotes
print "old: $string\n";
$string =~ s/@/\\@/;
sorry, make that:
$string =~ s/@/ \\ @ /;
 
J

jbauza

Thank you all for your prompt responses. I had tried all your solutions
already.

Problem was solved by using '@' instead of '@' when doing
either the substitution/splitting/index.
The string with the email is coming from a web page, if that explains
it.

Gunnar, I need to substitute the '@' for '\@' to be able to send an
email back to the user.
( the @ by itself does not work). We are running perl under red hat
linux.

Thanks to all again,
Joanna
 
J

jbauza

Funny, the string I typed was displayed as an '@'. Let me try again:

instead of '@' I had to use, I am going to add spaces in between so the
'@' is not displayed again, & # 0 6 4 ;
 
P

Paul Lalli

jbauza said:
Gunnar, I need to substitute the '@' for '\@' to be able to send an
email back to the user. ( the @ by itself does not work).

I find that remarkably unlikely. I find it far more likely that you
did something wrong. Unfortunately, you did not ask anyone about your
actual problem, only about your solution to the problem. You now
quite likely have an actual bug, and a big hack of a work around for
the bug in your system. You have made things worse, not better.

Paul Lalli
 
J

Joe Smith

jbauza said:
Gunnar, I need to substitute the '@' for '\@' to be able to send an
email back to the user.

In that case, you are doing something wrong.
There is no need to use \@ when working with a proper mailer.

Are you doing something like using double quotes where they are not
needed? Or, horrors, passing it to system("/usr/lib/sendmail $x")?

Anyway, to answer the question stated in the Subject line of your
posting: use
$string =~ s/\\@/@/g;
to substitute "@" for "\@" in a string.

-Joe
 
J

Josef Moellers

Joe said:
In that case, you are doing something wrong.
There is no need to use \@ when working with a proper mailer.

Are you doing something like using double quotes where they are not
needed? Or, horrors, passing it to system("/usr/lib/sendmail $x")?

Anyway, to answer the question stated in the Subject line of your
posting: use
$string =~ s/\\@/@/g;
to substitute "@" for "\@" in a string.

-Joe

using off better are You
$string =~ s/\@/\\\@/g;
;-)

fesoJ
 
J

jbauza

That statement does not work. I only worked when I used & # 0 6 4
instead of the @ sign.
( I added spaces in between & # ..., otherwise an @ sign will be
displayed when the message is posted)
Thanks
 
J

jbauza

The email is coming from a web page. I am not using double quotes, just
passing along the variable with the email.

This is how the msg is being sent:

$SendMail = "mail -s ' some text here' $MailUser";
open( MAIL, "| $SendMail ") or die "$$: Can't run $SendMail: $!";
select MAIL;

$MailUser is read from a web form, I am not setting it.
Please let me know if there is a better way of doing this.

Like I mentioned before, the substitution of the plain @ sign does not
work. I needed to use & # 0 6 4 ; to be able to either substitute, find
the index or split the string at the @ sign. ( no spaces in between the
& # 0 ...)
 
D

DJ Stunks

Joe said:
Are you doing something like using double quotes where they are not
needed? Or, horrors, passing it to system("/usr/lib/sendmail $x")?
I am not using double quotes, just
passing along the variable with the email.
$SendMail = "mail -s ' some text here' $MailUser";

boy, sure looks like double-quotes to me...

-jp
 
J

jbauza

Thank you for taking the time to reply.

Sorry for not asking the right question. That is what happens when you
are learning a new language. You do not even know where the problem
lies.

Do you have any solution for the real problem? I need to send and
email from a perl script, under red hat linux. What I am using now is
this:

$SendMail = "mail -s ' some text here ' $MailUser";
open( MAIL, "| $SendMail ") or die "$$: Can't run $SendMail: $!";
select MAIL;
# print "Content-type: text\/html\n\n\n";
print("************************************* \n");
print(" some other text here\n");
# print("************************************* \n");
close MAIL;

$MailUser is coming from a web form. If I leave it like it is, the
email does not go out. If I change the @ for \@, the email goes out
fine.

Thanks again,
Juana
 
J

jbauza

Nice article. Thank you for helping me come down from the high pedestal
where I was claiming to be. Thanks to you I am now very aware of my
"Own Incompetence..."
 
A

A. Sinan Unur

Sorry for not asking the right question. That is what happens when you
are learning a new language. You do not even know where the problem
lies.

Do you have any solution for the real problem? I need to send and
email from a perl script

Your question is frequently asked:

perldoc -q "send mail"

In addition, if you are sending HTML mail, you can use

http://search.cpan.org/~dskoll/MIME-tools-5.419/

http://search.cpan.org/~markov/MailTools-1.73/

and several other modules available on CPAN.

Sinan
 
A

A. Sinan Unur

That statement does not work.

What statement is that? Please quote some context when you post a reply.
I only worked when I used & # 0 6 4 instead of the @ sign.
( I added spaces in between & # ..., otherwise an @ sign will be
displayed when the message is posted)

Only if you are using something stupid like Google Groups ... oh ... I
see.

Sinan
 
R

robic0

The email is coming from a web page. I am not using double quotes, just
passing along the variable with the email.

This is how the msg is being sent:

$SendMail = "mail -s ' some text here' $MailUser";
open( MAIL, "| $SendMail ") or die "$$: Can't run $SendMail: $!";
select MAIL;

$MailUser is read from a web form, I am not setting it.
Please let me know if there is a better way of doing this.

Like I mentioned before, the substitution of the plain @ sign does not
work. I needed to use & # 0 6 4 ; to be able to either substitute, find
the index or split the string at the @ sign. ( no spaces in between the
& # 0 ...)


Hi jbauza,

I must be missing something, don't see what your problem is. You said it doesen't work.

You said $MailUser string is populated dynamically (from a function call?).

Any text that is in a string is in solution, stays in solution and never comes out.
That means it doesent matter how its used, it will always be the same (ergo even if quoted
several times).
So, I think your problem lies elsewhere as others have said.

------------------------
use strict;
use warnings;


my $MailUser = '(e-mail address removed)';

my $SendMail = "mail -s ' some text here' $MailUser";

print $SendMail,"\n";

__END__

mail -s ' some text here' (e-mail address removed)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top