Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: merging csv files into a third file preserving column & row

by Loops (Curate)
on Apr 01, 2013 at 12:02 UTC ( [id://1026467]=note: print w/replies, xml ) Need Help??


in reply to merging csv files into a third file preserving column & row

There have already been lots of good answers, but since i had already thrown this together, here it is for whatever value it might be. Cheers.
sub process_file { my ($hash, $file) = @_; open my $fh, "<", $file or die $!; while (<$fh>) { chomp; my ($target, @columns) = split /,/; $hash->{$target}[0] = $target; for my $c (0 .. $#columns) { $hash->{$target}[$c+1] .= $columns[$c]; } } close $fh; } $, = ','; print ("Now merging \n"); my $data = {}; process_file($data, $_) for glob("*.csv"); say @{$data->{$_}} for sort keys %$data;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found