Skip to content

Instantly share code, notes, and snippets.

@djanatyn
Created November 20, 2011 21:20
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/1380949 to your computer and use it in GitHub Desktop.
Save djanatyn/1380949 to your computer and use it in GitHub Desktop.
parsing facebook birthday files
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