Forked from bazzaar/gist:914a5c3e6fd69e45de7ecce9d16e360b
Last active
September 5, 2018 20:29
-
-
Save AlexDaniel/ae57c2937f49d6ab609aa1df0cb08a42 to your computer and use it in GitHub Desktop.
for loop with .lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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