how to replace "@" in a string

Posted on 2004-11-15
Last Modified: 2013-12-25
how to replace "@" in a string with "\@" without using any modules in cgi script?
Question by:jiniasp
    LVL 2

    Accepted Solution

    Assuming you have a variable holding the text that contains the "@" I would do somthing like this:

    var =~s/\@/\\\@/g;

    Since Perl (I am assuming) interprets the "@" as an array you would need to escape it for the regex to first find it and then replace it with the escaped version so the \@ used above will allow the @ to be found then the \\\@ is the escaped version.  I do believe this will work as expected.

    LVL 48

    Expert Comment

    I'll assume you are talking about a Perl/CGI script, so you can do:

    $string =~ s/@/\\@/;

    Why do you want to do this anyway?

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
    Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now