grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I have a series of files in a series of directories, I would like to merge the contents of all the files into one big fat csv file, which would go in a new location. files are csv formatted, want to make a giant csv that will be used to input the data from the files into sql. I would like to make it recursive from dirpath to end of tree and put the file generated into a different location..I have something like this which creates the csv but I am stumped on how to make it a regular script. perl -F -lane '@F %2 and push @D,{q{Stamp},@F} or $D-1={% {$D-1},@F}}{$,=",";print @{$_}{qw(Stamp Login searchload)}for @D' input.txt

Replies are listed 'Best First'.
Re: file copy and create csv problems
by kyle (Abbot) on Apr 14, 2009 at 14:58 UTC

    Here's a decryption of the code you have, using B::Deparse.

    BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; our(@F) = split(//, $_, 0); $D[-1] = {%{$D[-1]}, @F} unless @F % 2 and push @D, {'Stamp', @F}; } { $, = ','; print @{$_}{'Stamp', 'Login', 'searchload'} foreach (@D); }

    I'm not sure how much use that is, but it's more comprehensible than what you posted.

Re: file copy and create csv problems
by jrsimmon (Hermit) on Apr 14, 2009 at 15:33 UTC
    Please use code tags and see How do I post a question effectively?. Why do you want recursion? That seems unlikely to provide any benefit and will introduce the risk of overrunning your stack. A depth-first approach would seem to be best if order is not important, given what you've told us.