Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v6;
- #collect names of csv files in folder; establish header row trackera and open file for writing
- my @csv-files = './'.IO.dir(test => / '.csv' /)>>.basename;
- my $header-inserted = 0;
- my $wh = open "combined.csv", :a;
- #iterate through each file, writing the header-row only once and writing the rest of the contents out
- for @csv-files -> $file {
- my @contents = $file.IO.lines;
- if $header-inserted == 0 {
- for @contents -> $line {
- $wh.say($line);
- }
- $header-inserted = 1;
- }
- if $header-inserted == 1 {
- shift @contents; #gets rid of the header row since one has already been added
- for @contents -> $line {
- $wh.say($line);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement