Created
September 5, 2018 20:19
-
-
Save bazzaar/914a5c3e6fd69e45de7ecce9d16e360b to your computer and use it in GitHub Desktop.
for loop with .lines
This file contains 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 = Text::CSV.new (eol => "\n"); | |
my $cols = 49; | |
my @IO-object-list = 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
user1@laptop:~/CommaProjects/animals> perl6 animals.p6
===SORRY!=== Error while compiling /home/user1/CommaProjects/animals.p6
Unsupported use of -> as postfix; in Perl 6 please use either . to call a method, or whitespace to delimit a pointy block
at /home/user1/CommaProjects/animals.p6:22 [<<< this not actual line no]
------> for $contents.lines ->⏏ Str $line {
expecting any of:
dotty method or postfix
postfix