Last active
December 19, 2020 20:05
-
-
Save er2/b26c77e6a35e6f83472a6520da25bb38 to your computer and use it in GitHub Desktop.
I saw this Expressive C++17 challenge going around and felt like solving it in Perl 6
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
sub MAIN($input, Str $column, Str $replacement, IO::Path $output="output.csv".IO) { | |
my Str $headings = $input.IO.lines[0]; | |
my $index = $headings.split(",").antipairs.hash{$column}; | |
die "column $column not found" unless $index ~~ Int:D; | |
my $fh = open $output, :w; | |
LEAVE close $fh; | |
for $input.IO.lines.skip: 1 -> $line { | |
my @arr = $line.split(","); | |
@arr[$index] = $replacement; | |
$fh.say(@arr.join(",")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment