http://qs321.pair.com?node_id=170407

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

I feel sort of stupid asking what seems such an easy question, but I will ask it anyway.

I want to print an email address and name in the following form
first last <email>
I wrote some simple code to print this but I don't get the output I expect. Here is my output.
'first last '
Here is my code.
use strict; my $firstName = 'first'; my $lastName = 'last'; my $email = 'email@email.com'; print "$firstName $lastName \<$email\>";
What am I doing wrong here?

Replies are listed 'Best First'.
Re: Should be simple, What don't I see?
by Armos (Scribe) on May 30, 2002 at 15:14 UTC
    Hrm, that works for me. Are you looking at the output in something like a web browser, that might eat the tagged output?
      and if that's the case you could use &lt; and &gt;
      Yeah, that was it. I don't know why that didn't occur to me.
Re: Should be simple, What don't I see?
by dev2000 (Sexton) on May 30, 2002 at 15:36 UTC
    The browser expected a tag. Use this:
    use strict; my $firstName = 'first'; my $lastName = 'last'; my $email = 'email@email.com'; print "$firstName $lastName &lt;$email&gt;";
    or choose another set of braces for your {email} address.
Re: Should be simple, What don't I see?
by Aristotle (Chancellor) on May 31, 2002 at 00:29 UTC
    use strict; use HTML::Entities (); my $firstName = 'first'; my $lastName = 'last'; my $email = 'email@email.com'; # do it The One Correct Way print HTML::Entities::encode("$firstName $lastName <$email>");
    See also: perl.com: Preventing Cross-site Scripting Attacks

    Makeshifts last the longest.

Re: Should be simple, What don't I see?
by krujos (Curate) on May 30, 2002 at 15:19 UTC
    I tested this and it did exactly what you wanted.
    C:\Documents and Settings\jkruck.ENTERPRISE\Desktop>perl test.pl first last <email@email.com>
A reply falls below the community's threshold of quality. You may see it by logging in.