Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Perl problem w/HTML

Status
Not open for further replies.

salewit

Programmer
Oct 31, 2002
58
US
I can't figure this one out. In a Perl program, here's what I got:

$test = "Two Words";

print &quot;<input type=\&quot;text\&quot; name=\&quot;foo\&quot; value=$test>\n&quot;;


When I run the script, instead of getting &quot;Two Words&quot; in the form box, I get just the first word &quot;Two&quot;.

I can't figure this out. I changed the line to this:

print &quot;<input type=\&quot;text\&quot; name=\&quot;foo\&quot; value=$test>$test\n&quot;;

And I get:

Two Two Words

(the first Two is in the text box)

Can anybody help me with this?
 
Try changing the print line to look like:
Code:
print &quot;<input type=\&quot;text\&quot; name=\&quot;foo\&quot; value=\&quot;$test\&quot;>\n&quot;;
The value attribute is only picking up the first word so it needs to be enclosed in double quotes.
 
Perl provides the q and qq quote-like operators to help avoid ugly-looking code like that. Try
Code:
    print qq{<input type=&quot;text&quot; name=&quot;foo&quot; value=&quot;$test&quot;>
    };
or, better,
Code:
    use CGI qw/:standard :shortcuts/;
    use CGI::Carp qw/ fatalsToBrowser warningsToBrowser /;

    print textfield(-name=>'foo',default=>$test);

The CGI library is easy to use and hides all the underlying complexity of URI encoding/decoding, XHTML-compliance, etc, etc so why reinvent the wheel?

Yours,


fish


&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top