Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.68 KB | None | 0 0
  1. use v6;
  2.  
  3. #collect names of csv files in folder; establish header row trackera and open file for writing
  4. my @csv-files = './'.IO.dir(test => / '.csv' /)>>.basename;
  5. my $header-inserted = 0;
  6. my $wh = open "combined.csv", :a;
  7.  
  8. #iterate through each file, writing the header-row only once and writing the rest of the contents out
  9. for @csv-files -> $file {
  10.   my @contents = $file.IO.lines;
  11.   if $header-inserted == 0 {
  12.     for @contents -> $line {
  13.       $wh.say($line);
  14.     }
  15.       $header-inserted = 1;
  16.   }
  17.   if $header-inserted == 1 {
  18.     shift @contents; #gets rid of the header row since one has already been added
  19.     for @contents -> $line {
  20.       $wh.say($line);
  21.     }
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement