Skip to content

Instantly share code, notes, and snippets.

@JJ
Created November 30, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/ae1f08944d60f6fa8ba7bd8906967b0e to your computer and use it in GitHub Desktop.
Save JJ/ae1f08944d60f6fa8ba7bd8906967b0e to your computer and use it in GitHub Desktop.
Read and convert a CSV file - first version
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