Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Should be simple, What don't I see?

by fenonn (Chaplain)
on May 30, 2002 at 15:06 UTC ( #170407=perlquestion: print w/replies, xml ) Need Help??

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 = ''; 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 = ''; 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 = ''; # do it The One Correct Way print HTML::Entities::encode("$firstName $lastName <$email>");
    See also: 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 first last <>
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2023-02-09 05:14 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (44 votes). Check out past polls.