Skip to content

Instantly share code, notes, and snippets.

@tommystanton
Last active July 10, 2019 02:37
Show Gist options
  • Save tommystanton/7b5213f1e222f825f0e73648d5540a7f to your computer and use it in GitHub Desktop.
Save tommystanton/7b5213f1e222f825f0e73648d5540a7f to your computer and use it in GitHub Desktop.
Perl 6 script to convert dates to ISO8601
#!/usr/bin/env perl6
use v6.d;
=begin DESCRIPTION
Given a newline-delimited file of mm/dd/yyyy, write a newline-delimited
file of yyyy-mm-dd.
=end DESCRIPTION
my $in = 'dates.txt'.IO;
my $out = 'dates_iso_8601.txt'.IO;
$out.spurt('');
for $in.lines {
m/
$<month> = (\d ** 1..2)
\/
$<day> = (\d ** 1..2)
\/
$<year> = (\d ** 4)
/;
my $date = Date.new($<year>, $<month>, $<day>);
$out.spurt("{ $date.yyyy-mm-dd }\n", :append);
}
@tommystanton
Copy link
Author

Thank you so much for the code review, @lizmat! I've seen the $*OUT trick but have yet to try it (and didn't think to in this context), so I will check it out. 😎

Thank you especially for all of your hard work on the Perl 6 project; I am a huge fan and I am extremely grateful for how the language is coming along.

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