Skip to content

Instantly share code, notes, and snippets.

@bazzaar
Created September 5, 2018 20:19
Show Gist options
  • Save bazzaar/914a5c3e6fd69e45de7ecce9d16e360b to your computer and use it in GitHub Desktop.
Save bazzaar/914a5c3e6fd69e45de7ecce9d16e360b 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 = 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;
}
@bazzaar
Copy link
Author

bazzaar commented Sep 5, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment