faqts : Computers : Programming : Languages : Perl : Common Problems : Data Structures

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 8 people (100%) answered Yes
Recently 8 of 8 people (100%) answered Yes

Entry

How do I save a complex data-structure to disk?

Jun 16th, 2001 11:10
Per M Knutsen,


Use the use Data::Dumper module from CPAN.
# call the dumper module
use Data::Dumper;
... create your structure here
# Call sub-routine
dump_struc(\%structure);
# sub-routine for dumping structures to disk.
sub dump_struc {
    my ($struc) = @_;
    open (OUTPUT_FILE, "> $output_file") || die "cannot open file";
    print OUTPUT_FILE Data::Dumper->Dump([$struc], ['*structure']);
    close OUTPUT_FILE;
}