cayenne has asked for the wisdom of the Perl Monks concerning the following question:

I have a CGI scipt that is going to have two hashes of hashes and two hashes of arrays of data stored on the computer. It needs to get that data in each time it runs and occasionally save things.

Anyway. In the last version of this script I was reading from and printing to text documents in a rather inefficient way. Today I came across mention of the Data::Dumper module. It sounds like it would be incredibly useful, but I was confused by the man page (probably because I've never used objects, or modules for that matter.)

If anyone could tell me just how to get my hashes out using this and how to get them back in again it would be very much appreciated.

Thanks,
Cayenne

Replies are listed 'Best First'.
Re: basic Data::Dumper
by arturo (Vicar) on May 17, 2001 at 05:31 UTC

    Here's a link you may find helpful in this regard:: RE: Data::Dumper (Adam: Sample Usage). (I found that by searching on "Data::Dumper" by the way)

    A different, but nice and fast, solution would be to use Storable and its freeze and thaw methods. Storable is pretty good at storing and retrieving complex data structures into and from files.

    HTH!

    perl -e 'print "How sweet does a rose smell? "; chomp $n = <STDIN>; $r +ose = "smells sweet to degree $n"; *other_name = *rose; print "$other +_name\n"'
(jeffa) Re: basic Data::Dumper
by jeffa (Bishop) on May 17, 2001 at 06:19 UTC
    Data::Dumper is really quite easy to use:
    use Data::Dumper; print Dumper $some_var;
    You said this was for a CGI script, if you have access to the error log, you can tail -f it and print to STDERR:
    print STDERR Dumper %hash_of_hashes;
    If you don't know what the error log is and would rather just print it to the browser, be sure and use pre tags:
    print "<pre>\n", Dumper %hash_of_arrays, "</pre>\n";
    Hope this helps.

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    

      The output from Dumper %hash isn't nearly as easy to read as the output from Dumper \%hash.

              - tye (but my friends call me "Tye")
Re: basic Data::Dumper
by merlyn (Sage) on May 17, 2001 at 18:16 UTC