Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Is it possible to print out CGI fields using the qq operator?

by hok_si_la (Curate)
on Feb 22, 2005 at 22:04 UTC ( #433505=perlquestion: print w/ replies, xml ) Need Help??
hok_si_la has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to avoid the following syntax structures.
###-- using cgi.pm print qq{ <sometag> }; print textfield(-name=>'cgifield',-size=>'20'); print qq{ <sometag> };

Comment on Is it possible to print out CGI fields using the qq operator?
Download Code
Re: Is it possible to print out CGI fields using the qq operator?
by kutsu (Priest) on Feb 22, 2005 at 22:35 UTC

    As far as I know you cannot, as tye put it on the chatterbox:

    data structure dereferencing is interpretted inside of double quotes, but method calls and code dereferencing aren't

    This is more easily seen if you use the OO form of CGI.pm:

    use CGI; $cgi = CGI->new; print "$cgi->textfield(-name=>'cgifield',-size=>'20')"; print qq/$cgi->textfield(-name=>'cgifield',-size=>'20')/; print <<EOL; $cgi->textfield(-name=>'cgifield',-size=>'20') EOL #all print CGI=HASH(0x...)
Re: Is it possible to print out CGI fields using the qq operator?
by hossman (Prior) on Feb 23, 2005 at 00:47 UTC
Re: Is it possible to print out CGI fields using the qq operator?
by BUU (Prior) on Feb 23, 2005 at 01:16 UTC
    Better yet, either use a "Real Templating Engine" (such as HTML::Template) or just manually create your html inside strings, don't mix html in strings with CGI.pm's html functions, that's just ugly.
Re: Is it possible to print out CGI fields using the qq operator?
by chas (Priest) on Feb 23, 2005 at 02:01 UTC
    How about:
    use CGI qq(:standard); print qq{ <sometag> @{[textfield(-name=>'cgifield',-size=>'20')]} <sometag> };

    (This prints:
    <sometag>
    <input type="text" name="cgifield" size="20" />
    <sometag>

    Admittedly, it is still a bit cumbersome...
    chas
    (I'm a little confused about why the /> instead of >. The code by the hok si la also produces the same thing...) (Updated to fix typos, errors and formatting.)
      (I'm a little confused about why the /> instead of >. The code by the hok si la also produces the same thing...)

      That's because GGI.pm's HTML generation methods produce XHTML, rather than HTML 4. They have, in fact, been doing so for a long time, as enthusiastically pointed out by merlyn here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2014-07-29 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (220 votes), past polls