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

my code:
$string="name@domain.com"; print $string;
result:   name.com How do you parse this when it appears the string doesn't even contain the "@domain"?

What must the string contain to print "name@domain.com"?

Edit by dws for <code> tags

Replies are listed 'Best First'.
Re: printing/parsing string including "@"
by no_slogan (Deacon) on Sep 10, 2002 at 16:49 UTC
    kabel nailed it. Yet another reason to always use warnings;. If you had, you might have seen a warning message like this:
    > perl -e 'use warnings; my $string="name@domain.com"'
    Possible unintended interpolation of @domain in string at -e line 1.
    Name "main::domain" used only once: possible typo at -e line 1.
    
Re: printing/parsing string including "@"
by kabel (Chaplain) on Sep 10, 2002 at 16:41 UTC
    just put a backslash before the @ to "escape" it, or you put the string inside single quotes to avoid that the array stringifies.
Re: printing/parsing string including "@"
by suaveant (Parson) on Sep 10, 2002 at 16:48 UTC
    a \ before the @ will do it in double quotes, but if you don't need a string that interpolates variables, you can always use single quotes...
    "name\@domain.com" 'name@domain.com'
    this works for $, too

                    - Ant
                    - Some of my best work - (1 2 3)

Re: printing/parsing string including "@"
by davorg (Chancellor) on Sep 10, 2002 at 16:50 UTC

    Why not just use single quotes?

    $string = 'name@domain.com'; print $string;

    Double quoted strings expand variables. @domain looks like a variable. Therefore Perl tries to expand it - but it's empty.

    As usual, running with -w and use strict would have shown you what the problem was.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: printing/parsing string including "@"
by Pahrohfit (Sexton) on Sep 10, 2002 at 18:29 UTC
    Since @ is one of many "special", or reserved characters in Perl, you would need to do one of the following:
    $string = 'name@domain.com'; print $string; --or-- $string = "name\@domain.com"; print $string;
Re: printing/parsing string including "@"
by JP Sama (Hermit) on Sep 10, 2002 at 19:41 UTC
    well, it's a little strange to visit perlmonks after a long away period...

    But it's even stranger to see so many replies with the same answer to one simple question...

    #!/usr/bin/perl -w
    `mount`;
    print $! if $!;
    
Re: printing/parsing string including "@"
by Jasper (Chaplain) on Sep 11, 2002 at 15:28 UTC
    Is this a joke? Surely there are more worthy questions we could be looking at on the front page.

    Jasper
Re: printing/parsing string including "@"
by Anonymous Monk on Sep 10, 2002 at 22:27 UTC
    You need to escape the @

    example:

    $string = "name\@domain.com";<br> print $string;<br>

    result:

    name@domain.com
Re: printing/parsing string including "@"
by Anonymous Monk on Sep 11, 2002 at 14:48 UTC
    print "name\@domain.com\n";

    \n is optional.

    M