Skip to content

Instantly share code, notes, and snippets.

@AlexDaniel
Forked from bazzaar/gist:914a5c3e6fd69e45de7ecce9d16e360b
Last active September 5, 2018 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDaniel/ae57c2937f49d6ab609aa1df0cb08a42 to your computer and use it in GitHub Desktop.
Save AlexDaniel/ae57c2937f49d6ab609aa1df0cb08a42 to your computer and use it in GitHub Desktop.
for loop with .lines
#use Slang::Tuxic;
#use Text::CSV;
#use File::Find;
my $csv_line = ‘foo’; # Text::CSV.new (eol => "\n");
my $cols = 49;
my @IO-object-list = < a b c >; #find(:dir</home/user1/documents/animals>, :type<file>, :name(/armadillos_201<[4..8]>.*\.csv/));
for @IO-object-list -> $IO-object {
my $out = $IO-object.path.subst(/\.csv/, '_edit.csv');
my $fh = $out.IO.open: :w;
my $contents = $IO-object.slurp;
# for $contents.lines() -> Str $line { # this works
for $contents.lines -> Str $line { # this doesn't
if $csv_line.parse($line) {
if $csv_line.strings.elems lt $cols {
my $pad = ',' x ( $cols - $csv_line.strings.elems );
$fh.put: $line ~ $pad;
} else { $fh.put: $line }
}
}
$fh.close;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment