in reply to How to write complete hash into CSV?

One could argue that it is already in CSV format for a single very big cell ;)

So you could clarify your output as for example 'CSV: one row per hash key or array element, one indentation per substructure'. In which case a simple approach would be, for my own example definition: (Updated to process arrays nested in there)

my $csv = ''; traverse(0,$VAR1,\$csv,';'); sub traverse { my ($plevel, $node, $csvref, $dlm) = @_; if (ref($node) eq 'HASH')) { while (my ($k, $v) = each %$node) { $$csvref .= ($plevel x $dlm) . $k; if (ref($v)') { $$csvref .= "\n"; traverse($plevel+1, $v, $csvref, $dlm); } else { $$csvref .= $dlm . $v . "\n"; } } } else { # array. scalars are filtered before the recurse for my $elm (@$node) { if (ref($elm)) { traverse($plevel+1, $elm, $csvref, $dlm); } else { $$csvref .= ($plevel x $dlm) . $elm . "\n"; } } } }

One world, one people