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.

In reply to Re: I really need help with perl data structures and HTML::Template by perlmonkey
in thread I really need help with perl data structures and HTML::Template by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.