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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -