<?xml version="1.0" encoding="windows-1252"?>
<node id="140903" title="Debugging the CGI environment" created="2002-01-23 14:31:11" updated="2005-08-02 17:06:36">
<type id="1980">
snippet</type>
<author id="29008">
grinder</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
I finished a CGI script yesterday that did some fiddly things with various environment variables, and carried various settings in hidden form fields. It became a hassle to print out the various values of things from time to time, so in the end I just used the following snippet to dump (or not) the values of the environment and the CGI post parameters.&lt;/p&gt;
&lt;p&gt;Just flip from 0 to 1 when you need to display the contents to figure out what's what.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;[merlyn] is quite right. I have successfully reinvented the Dump method. Having played with both now, all I can say in my defense is that the output from this snippet is more compact.&lt;/p&gt;</field>
<field name="snippetcode">
&lt;CODE&gt;
# assuming my $q = new CGI;
0 and print $q-&gt;ul( $q-&gt;li( [ map { "env $_ =&gt; $ENV{$_}" } sort keys %ENV ] ));
1 and print $q-&gt;ul( $q-&gt;li( [ map { "param $_ =&gt; @{[$q-&gt;param($_)]}" } sort $q-&gt;param() ] ));
2 and print $q-&gt;Dump; # RTFM
&lt;/CODE&gt;</field>
</data>
</node>
