Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: I really need help with perl data structures and HTML::Template

by perlmonkey (Hermit)
on May 29, 2000 at 01:31 UTC ( [id://15226]=note: print w/replies, xml ) Need Help??


in reply to I really need help with perl data structures and HTML::Template

Whenever I start using any data structures, I use Data::Dumper profusely. Data::Dumper will simply print out the entire data structure with the proper reference notation. It is a great way to start debugging scripts when you dont understand the data you are dealing with. Of course lhoward's advice is definately more valuable: use strict. Here is an example of Data::Dumper
use Data::Dumper; my %hash = ('a'=>1, 'b'=>2, 'b'=>3); my @array = ('c','d','e','f'); my $data = {%hash}; $data->{'array'} = [@array]; $data->{'array'}[4] = {%hash}; $data->{'array'}[4]{'foobar'} = [@array]; print Data::Dumper->Dump([$data], ['data']);
Results:
$data = { 'a' => 1, 'b' => 3, 'array' => [ 'c', 'd', 'e', 'f', { 'foobar' => [ 'c', 'd', 'e', 'f' ], 'a' => 1, 'b' => 3 } ] };
And you can use it to print out any unknown object, such as a CGI object:
use CGI qw(:standard -debug); my $cgi = new CGI; print Data::Dumper->Dump([$cgi], ['cgi']);
I entered in values of 'foobar=val, and 'submit=sumbit' and the Results:
$cgi = bless( { '.charset' => 'ISO-8859-1', 'foobar' => [ 'val' ], '.parameters' => [ 'foobar', 'submit' ], 'submit' => [ 'sumbit' ], '.fieldnames' => {} }, 'CGI' );
The notations for {} mean hash references and the notation for [] is for array references.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://15226]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found