Created
November 20, 2011 21:20
-
-
Save djanatyn/1380949 to your computer and use it in GitHub Desktop.
parsing facebook birthday files
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
my $fh = open('birthdays.ics', :r); | |
my @index; | |
my $items = 0; | |
for $fh.lines -> $line { | |
if $line ~~ m/^DTSTART\:(.+)/ { | |
@index[$items] = []; | |
push @index[$items], $0; | |
}; | |
if $line ~~ m/^SUMMARY\:(.+)/ { | |
push @index[$items], $0; | |
print "."; | |
$items++; | |
}; | |
}; | |
print "\ndone\n"; | |
my %birthdays; | |
for @index -> $list { %birthdays{$list[0]} += 1; }; | |
my $max = @index[0][0]; | |
my $unique = 0; | |
for %birthdays.keys -> $date { | |
if %birthdays{$date} > %birthdays{$max} { $max = $date; }; | |
say "$date: %birthdays{$date} occurences "; | |
if %birthdays{$date} == 1 { | |
$unique++; | |
}; | |
}; | |
say "{ $items - 1 } entries"; | |
say "there were { %birthdays.elems } days that had a birthday"; | |
say "$unique people have unique birthdays"; | |
say "the most common birthday was $max with %birthdays{$max} birthdays!"; | |
say "they are the birthdays of:"; | |
for @index -> $dates { if $dates[0] == $max { say $dates[1]; }; }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment