Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

how to substitute '@' in line

by vishy_acts (Novice)
on Apr 08, 2012 at 17:09 UTC ( [id://964008]=perlquestion: print w/replies, xml ) Need Help??

vishy_acts has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I want to substitute '@' in email id with \@ .
I am processing one crontabe entry from our server which contains email id .
How to add escape character '\' before that so as to process it correctly .?

program:

$line="abc.xyz@lmnop.com"; $line=~s/\@/\\@/g; print "\n line is $line";

This is not giving correct result .

Thanks
Vishy

--------------------------------------------
I tried using Email::Address as follows

@addr=Email::Address->parse($line); $user=$addr->$user; print "\n $user";

---- this is not giving anything ---
i checked contents with perl -d ... addr is not getting created ...

please help

Replies are listed 'Best First'.
Re: how to substitute '@' in line
by johngg (Canon) on Apr 08, 2012 at 17:33 UTC

    Your line $line="abc.xyz@lmnop.com"; is using double-quotes so you are trying to interpolate the array @lmnop into the string. Use single-quotes to suppress interpolation.

    knoppix@Microknoppix:~$ perl -E ' > $line = q{abc.xyz@lmnop.com}; > say $line; > $line =~ s{(?=\@)}{\\}; > say $line;' abc.xyz@lmnop.com abc.xyz\@lmnop.com knoppix@Microknoppix:~$

    I hope this is helpful.

    Cheers,

    JohnGG

Re: how to substitute '@' in line
by Anonymous Monk on Apr 08, 2012 at 17:40 UTC
    I'm not at my computer with Perl installed, but I think you could use the substitution operator with non-interpolating delimiters.

    s'@'\@'

Re: how to substitute '@' in line
by snape (Pilgrim) on Apr 09, 2012 at 00:48 UTC

    Are you substituting @ to /@ or separating the id and domain name. This might give you some hints:

    my $line = 'abc.xyz@lmnop.com'; print $line,"\n"; $line=~s/($1)@($2)/$1\t$2/g; print "\n line is $line";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://964008]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-25 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found