Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: How do I merge every csv file in the directory?

by Jim (Curate)
on Jun 27, 2012 at 18:51 UTC ( #978746=note: print w/replies, xml ) Need Help??

in reply to How do I merge every csv file in the directory?

As you can see my weakness is actually getting all of the csv file names into an array. I think this is going to be solved with a map command but I wasn't able to figure it out myself.

Consider using @ARGV instead of hardwiring the input file names inside the script. And also consider using STDOUT instead of hardwiring the output file name inside the script.

I like File::Glob::bsd_glob().

#!perl use strict; use warnings; use English qw( -no_match_vars ); use File::Glob qw( bsd_glob ); @ARGV or die "Usage: perl $PROGRAM_NAME <CSV file> ...\n"; @ARGV = map { bsd_glob($ARG) } @ARGV; while (my $row = <ARGV>) { # Presumably, something useful happens to $row here; # otherwise this script is just cat(1) in Perl print $row; } exit 0;


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978746]
[Your Mother]: Roger, will co.
[Your Mother]: The good news is, they think they are influencing people but Americans at least are irretrievably biased. All that can be accomplished is a little spike in domestic violence. :P
[LanX]: YM: watch your mouth or I'll show up with my automatic gun at your nursery ...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2018-03-19 13:27 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.