Created
November 30, 2022 17:04
-
-
Save JJ/ae1f08944d60f6fa8ba7bd8906967b0e to your computer and use it in GitHub Desktop.
Read and convert a CSV file - first version
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 read-csv(IO() $file) { | |
gather { | |
my $f = $file.open: :r :!chomp; | |
with Text::CSV.new { | |
.header: $f, munge-column-names => { S:g /\W+//.samemark('x').lc }; | |
while my $row = .getline-hr: $f { take $row } | |
} | |
} | |
} | |
sub csv-to-yaml(@line --> Str) | |
# secret sauce | |
my %obj = do { ... }; | |
to-yaml %obj | |
} | |
sub server-put($_) { | |
# HTTP::UserAgent | |
} | |
sub MAIN(Str $input) { | |
my @r = lazy read-csv $input; | |
server-login; | |
server-put csv-to-json $_ for @r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment