perl - Dumping hash of arrays to file -
how can dump hash of arrays file?
each hash keys name of folder , array of files listed in folder.
here working on,
open outfile, "> output.txt" or die $!; foreach $key (keys %folder_structure) { print outfile "$key\n"; foreach $line (@{$folder_structure{$key}}) { print outfile "$line\n"; } } close outfile;
if not have specific requirement output format, simplest way use data::dumper:
use strict; use data::dumper; open outfile, "> output.txt" or die $1; print outfile dumper \%folder_structure; close outfile;
edit: per comments, dumper
being passed reference hash, not hash itself.
the data::dumper module has settings control output, can read on cpan page.
Comments
Post a Comment