in reply to Convert hash to CSV using Text::CSV::Slurp
I wonder why I need Text::CSV::Slurp? Am I missing something? Will the above code break when passed other sorts of data?my @cols; my @row; sub hash2csv { my $h = shift; my $p = shift || 'top'; foreach my $k ( keys %{$h} ) { if (ref $h->{$k} eq ref {}) { hash2csv( $h->{$k}, $k ); } else { if ( $p eq 'top' ) { push @cols, $k; } else { push @cols, "$p.$k"; } push @row, $h->{$k}; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Convert hash to CSV using Text::CSV::Slurp
by Laurent_R (Canon) on May 16, 2015 at 12:14 UTC | |
|
Re^2: Convert hash to CSV using Text::CSV::Slurp
by Laurent_R (Canon) on May 16, 2015 at 11:59 UTC | |
by Plankton (Vicar) on May 17, 2015 at 19:56 UTC |