Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 = '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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2019-06-20 19:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (91 votes). Check out past polls.

    Notices?