Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
PerlMonks  

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

by hok_si_la (Curate)
on Feb 22, 2005 at 17:04 UTC ( [id://433505]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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> };

Replies are listed 'Best First'.
Re: Is it possible to print out CGI fields using the qq operator?
by kutsu (Priest) on Feb 22, 2005 at 17: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 22, 2005 at 19:47 UTC
Re: Is it possible to print out CGI fields using the qq operator?
by BUU (Prior) on Feb 22, 2005 at 20: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 22, 2005 at 21: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
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://433505]
Approved by davido
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.