Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created October 31, 2011 02:06
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 djanatyn/1326748 to your computer and use it in GitHub Desktop.
Save djanatyn/1326748 to your computer and use it in GitHub Desktop.
facebook birthday parser
my $fh = open('birthdays.ics', :r);
my @dates;
my @names;
for $fh.lines -> $line {
if $line ~~ m/^DTSTART\:(.+)/ { push @dates, $0; }
if $line ~~ m/^SUMMARY\:(.+)/ { push @names, $0; }
}
my $x = 0;
my @index;
for @dates -> $date {
push @index, [$date, @names[$x]];
$x++;
};
my %birthdays;
for @index -> $list { %birthdays{$list[0]} += 1; }
my @max = (0,0);
for %birthdays.keys -> $date {
if %birthdays{$date} > @max[1] {
@max[0] = $date;
@max[1] = %birthdays{$date};
}
say "$date: %birthdays{$date} occurences"; }
say "the most common birthday was @max[0] with @max[1] birthdays!";
#< output:
20120101: 2 occurences
20120103: 2 occurences
20120104: 1 occurences
20120105: 5 occurences
20120106: 1 occurences
20120107: 1 occurences
20120108: 1 occurences
20120111: 2 occurences
20120112: 3 occurences
20120113: 1 occurences
20120114: 1 occurences
20120115: 3 occurences
20120117: 2 occurences
... #>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment