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

Discussion in 'Perl Misc' started by jbauza, Feb 9, 2006.

  1. jbauza

    jbauza Guest

    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
    jbauza, Feb 9, 2006
    #1
    1. Advertising

  2. jbauza wrote:
    > 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 = ''; # note the single quotes
    print "old: $string\n";
    $string =~ s/@/\\@/;
    print "new: $string\n";
    it_says_BALLS_on_your forehead, Feb 9, 2006
    #2
    1. Advertising

  3. it_says_BALLS_on_your forehead wrote:
    > jbauza wrote:
    > > 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 = ''; # note the single quotes
    > print "old: $string\n";
    > $string =~ s/@/\\@/;

    sorry, make that:
    $string =~ s/@/ \\ @ /;

    > print "new: $string\n";
    it_says_BALLS_on_your forehead, Feb 9, 2006
    #3
  4. Gunnar Hjalmarsson, Feb 9, 2006
    #4
  5. Jim Gibson wrote:
    > In article <>,
    > jbauza <> wrote:
    >
    > > 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.

    >
    > Mr. Forehead showed you how to use the substitution operator. The split


    Please Jim, Mr. Forehead is my dad.
    it_says_BALLS_on_your forehead, Feb 10, 2006
    #5
  6. jbauza

    jbauza Guest

    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
    jbauza, Feb 10, 2006
    #6
  7. jbauza

    jbauza Guest

    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 ;
    jbauza, Feb 10, 2006
    #7
  8. jbauza

    Paul Lalli Guest

    jbauza wrote:
    > 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
    Paul Lalli, Feb 10, 2006
    #8
  9. Gunnar Hjalmarsson <> wrote:
    > jbauza wrote:
    >> I need to replace the '@' from an email address to read ' \ @ '.

    >
    > Why do you need that?
    >


    And how does that relate to what is in the Subject header?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 10, 2006
    #9
  10. "Paul Lalli" <> wrote in news:1139603654.995688.97780
    @g43g2000cwa.googlegroups.com:

    > jbauza wrote:
    >> 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.


    http://www.phule.net/mirrors/unskilled-and-unaware.html

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 11, 2006
    #10
  11. jbauza

    Joe Smith Guest

    jbauza wrote:

    > 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
    Joe Smith, Feb 12, 2006
    #11
  12. Joe Smith wrote:
    > jbauza wrote:
    >
    >> 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


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

    fesoJ
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
    Josef Moellers, Feb 13, 2006
    #12
  13. jbauza

    jbauza Guest

    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
    jbauza, Feb 14, 2006
    #13
  14. jbauza

    jbauza Guest

    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 ...)
    jbauza, Feb 14, 2006
    #14
  15. jbauza

    DJ Stunks Guest

    Joe Smith wrote:

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


    jbauza wrote:
    > 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
    DJ Stunks, Feb 14, 2006
    #15
  16. jbauza

    jbauza Guest

    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
    jbauza, Feb 14, 2006
    #16
  17. jbauza

    jbauza Guest

    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..."
    jbauza, Feb 14, 2006
    #17
  18. "jbauza" <> wrote in news:1139945682.303802.216740
    @o13g2000cwo.googlegroups.com:

    > 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. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 14, 2006
    #18
  19. "jbauza" <> wrote in news:1139944313.089586.61240
    @z14g2000cwz.googlegroups.com:

    > 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

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Feb 14, 2006
    #19
  20. jbauza

    robic0 Guest

    On 14 Feb 2006 11:23:23 -0800, "jbauza" <> wrote:

    >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 = '';

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

    print $SendMail,"\n";

    __END__

    mail -s ' some text here'
    robic0, Feb 14, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Kish
    Replies:
    2
    Views:
    916
    Jeff Kish
    Nov 15, 2004
  2. Lingyun Yang
    Replies:
    2
    Views:
    499
    Daniel T.
    Apr 10, 2004
  3. Replies:
    7
    Views:
    776
    Pasi Savolainen
    Feb 26, 2006
  4. Casanova

    Macro without string to substitute

    Casanova, Nov 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    394
    Richard Bos
    Nov 24, 2004
  5. Casanova

    Macro without string to substitute

    Casanova, Nov 21, 2004, in forum: C Programming
    Replies:
    1
    Views:
    398
    Robert Gamble
    Nov 21, 2004
Loading...

Share This Page