Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Introducing a character in a string

Reply
Thread Tools

Introducing a character in a string

 
 
Arun Kumar
Guest
Posts: n/a
 
      01-17-2005
Hi,

I want to introduce a special character ( \ ) in a string using perl script.
(i.e) "" has to be converted into "first.last\@mail.com".
Please help me.

Regards,
Arunkumar
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      01-17-2005
"Arun Kumar" <> wrote in message
news: m...
> I want to introduce a special character ( \ ) in a string using perl

script.
> (i.e) "" has to be converted into

"first.last\@mail.com".
> Please help me.


Have you read any documentation or tutorials about regular expressions?
That would be a very good place to start:

perldoc perlretut

Specifically, you want to use the search-and-replace operators s///.

If you have read it and understand regular expressions, please post a
short but complete piece of code demonstrating what you've tried so far
and how it has failed to function as you'd like it to.

Paul Lalli

 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      01-17-2005
Arun Kumar wrote:
> Hi,
>
> I want to introduce a special character ( \ ) in a string using perl script.
> (i.e) "" has to be converted into "first.last\@mail.com".
> Please help me.


The answer depends upon the question:
Why would you need it?

If you need it because perl complains about "Possible unintended
interpolation of @mail in string", then just insert the backslash
character using your favorite editor.

If you _think_ you need the backslash because the @ is a special
character and you _think_ that perl might get confused: it won't. If you
read "" from some place (e.g. STDIN, some file), then
the @ won't be regarded as a special character any more. Introducing a
backslash will only introduce one more character, a character you don't
really want.

If you still are convonced you need the backslash:

$s = '';
$s =~ s/\@/\\$&/;

HTH,

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string with control character in caret notation to realcontrol character string. Bart Vandewoestyne C Programming 8 09-25-2012 12:41 PM
FAQ 4.31 How can I split a [character] delimited string except when inside [character]? PerlFAQ Server Perl Misc 0 01-25-2011 05:00 AM
How can I replace all occurrences of a character with another character in std string? herman C++ 5 08-30-2007 09:05 AM
8 bit character string to 16 bit character string Brand Bogard C Programming 8 05-28-2006 05:05 PM
getting the character code of a character in a string Velvet ASP .Net 9 01-19-2006 09:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57