Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

file copy and create csv problems

by grashoper (Monk)
on Apr 14, 2009 at 14:32 UTC ( [id://757400]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://757400]
Approved by linuxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-26 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found