Home > Archive > PERL CGI Beginners > October 2006 > Dumping all vars
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| J. Alejandro Ceballos Z. -JOAL- 2006-10-03, 9:55 pm |
|
The variables created during a cgi, are stored in some kind of hash,
like the %ENV enviroment variables?
I want to create in some points, a var dump of all variables existed, in
order to track errors.
Atentamente,
,_,
(O,O) J. Alejandro Ceballos Z. buzon@alejandro.ceballos.info
( )
-"-"-----------------------------------------------------------------
http://alejandro.ceballos.info movil: (33) 3849-8936
| |
| Tyler Gee 2006-10-03, 9:55 pm |
| Part of the CGI module:
http://search.cpan.org/~lds/CGI.pm-..._YOUR_SCRIPT%3A
On 10/3/06, J. Alejandro Ceballos Z. -JOAL-
<buzon@alejandro.ceballos.info> wrote:
>
> The variables created during a cgi, are stored in some kind of hash,
> like the %ENV enviroment variables?
>
> I want to create in some points, a var dump of all variables existed, in
> order to track errors.
>
>
> Atentamente,
>
> ,_,
> (O,O) J. Alejandro Ceballos Z. buzon@alejandro.ceballos.info
> ( )
> -"-"-----------------------------------------------------------------
> http://alejandro.ceballos.info movil: (33) 3849-8936
>
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
--
~Tyler
| |
| Mumia W. 2006-10-03, 9:55 pm |
| On 10/03/2006 09:19 PM, J. Alejandro Ceballos Z. -JOAL- wrote:
>
> The variables created during a cgi, are stored in some kind of hash,
> like the %ENV enviroment variables?
>
> I want to create in some points, a var dump of all variables existed, in
> order to track errors.
>
Perhaps the Data::Dumper module will help you.
| |
| Paul Lalli 2006-10-04, 7:55 am |
| Mumia W. wrote:
> On 10/03/2006 09:19 PM, J. Alejandro Ceballos Z. -JOAL- wrote:
>
> Perhaps the Data::Dumper module will help you.
Oy. Not if the OP doesn't know where the variables are, which is what
the OP specifically asked.
Alejandro, the variables are not stored in any built-in variable (at
least not in any easily usable format). Instead, you can use CGI.pm's
param() function to get a list of all the parameters:
my %params;
for my $name (param()) {
my @values = param($name);
$params{$name} = ( @values > 1 ? \@values : $values[0] );
}
This will make a hash whose keys are the names of the parameters passed
in, and values are the values of the parameters passed in. Any
parameter that has multiple values will be stored as a reference to an
array.
Alternatively, you can use CGI's Vars() function to get the hash
directly:
my %params = Vars();
However, in this hash, any multi-valued parameters are stored as single
strings with each value separated by the \0 character. If you want to
convert this to the structure described above, you could do so like:
for my $value (values %params) {
my @values = split "\0", $value;
$value = \@values if @values > 1;
}
Once you have your parameter hash as you like it, then, as Mumia said,
you can use Data::Dumper:
use Data::Dumper;
print Dumper(\%params);
Paul Lalli
| |
| Paul Lalli 2006-10-04, 7:55 am |
| J. Alejandro Ceballos Z. -JOAL- wrote:
> The variables created during a cgi, are stored in some kind of hash,
> like the %ENV enviroment variables?
>
> I want to create in some points, a var dump of all variables existed, in
> order to track errors.
>
If all you're looking for is an HTML printout of the parameters passed
in, you can use CGI.pm's Dump() function to create such a list:
print Dump();
Paul Lalli
| |
| J. Alejandro Ceballos Z. -JOAL- 2006-10-05, 9:55 pm |
| With the parameters are not problem
(in fact I use the followin code for that - $cgi_this is the CGI object -:
foreach $str_param ($cgi_this->param)
{ print "\n $str_param: \t" . $cgi_this->param($str_param); } )
I want to make a var dump with the vars existing at some moment of the
code, in order to debug my code. The idea is to implement some function
or piece of code that do that, so just call it at certain point to see
the values of all existing vars at that moment.
Are around 30 vars operating at same moment, some of them only exist in
one block of code and later dissapear. Thats why I planned a var dump.
> Part of the CGI module:
> http://search.cpan.org/~lds/CGI.pm-..._YOUR_SCRIPT%3A
--
Atentamente,
,_,
(O,O) J. Alejandro Ceballos Z. buzon@alejandro.ceballos.info
( )
-"-"-----------------------------------------------------------------
http://alejandro.ceballos.info movil: (33) 3849-8936
| |
| Tyler Gee 2006-10-06, 7:55 am |
| On 10/5/06, J. Alejandro Ceballos Z. -JOAL-
<buzon@alejandro.ceballos.info> wrote:
> With the parameters are not problem
>
> (in fact I use the followin code for that - $cgi_this is the CGI object -:
> foreach $str_param ($cgi_this->param)
> { print "\n $str_param: \t" . $cgi_this->param($str_param); } )
>
> I want to make a var dump with the vars existing at some moment of the
> code, in order to debug my code. The idea is to implement some function
> or piece of code that do that, so just call it at certain point to see
> the values of all existing vars at that moment.
>
> Are around 30 vars operating at same moment, some of them only exist in
> one block of code and later dissapear. Thats why I planned a var dump.
Data::Dumper like Mumia suggested.
Or Smart::Comments.
>
>
>
> --
> Atentamente,
>
> ,_,
> (O,O) J. Alejandro Ceballos Z. buzon@alejandro.ceballos.info
> ( )
> -"-"-----------------------------------------------------------------
> http://alejandro.ceballos.info movil: (33) 3849-8936
>
>
>
>
>
--
~Tyler
|
|
|
|
|