Skip to content

Instantly share code, notes, and snippets.

@cowens
Created July 7, 2009 14:50
Show Gist options
  • Save cowens/142116 to your computer and use it in GitHub Desktop.
Save cowens/142116 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
my $year = qr{
(?<year>
(?<century> 1 [6-9]) (?<decade>[0-9]{2}) |
(?<century> [2-9] [0-9]) (?<decade> [0-9]{2})
)
}x;
for my $s (1984, 2009) {
my @parts = $s =~ $year;
print "for $s parts are ", join(", ", map { $_ // "undef" } @parts), "\n",
"year is $+{year}, century is $+{century}, and decade is $+{decade}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment