#!/usr/bin/perl -w use strict; use Date::Calc qw(Day_of_Year); # Format of monkdays.txt # marto:01-28:11-30 # :: my $monkfile = "monkdays.txt"; my %monks; open MONKS, "<$monkfile" or die "Ugh:$!\n"; while () { chomp; my ($nick, $joined, $bday) = split(/:/, $_); $monks{$nick}{joined} = $joined; $monks{$nick}{bday} = $bday; # Calculate the julian day for each date, and add to hash $monks{$nick}{jday_joined} = Day_of_Year("2006", split(/-/, $joined)); $monks{$nick}{jday_bday} = Day_of_Year("2006", split(/-/, $bday)); # Now, calculate the delta (in days) between birthdate and joined date $monks{$nick}{delta} = ($monks{$nick}{jday_joined} > $monks{$nick}{jday_bday}) ? ($monks{$nick}{jday_joined} - $monks{$nick}{jday_bday}) : ($monks{$nick}{jday_bday} - $monks{$nick}{jday_joined}); } close MONKS; print "Total Monks with birthdays:", scalar (keys %monks), "\n\n"; print "Monks who joined within 10 days of their birthday:\n\n"; printf "%-20s %-10s %-10s %-5s", "Monk", "Joined", "Birthday", "Delta"; print "\n"; foreach my $monk (sort by_delta keys %monks) { last if $monks{$monk}{delta} > 10; printf "%-20s %-10s %-10s %-5s", "$monk", "$monks{$monk}{joined}", "$monks{$monk}{bday}", "$monks{$monk}{delta}"; print "\n"; } sub by_delta { return $monks{$a}{delta} <=> $monks{$b}{delta}; } #### Total Monks with birthdays:432 Monks who joined within 10 days of their birthday: Monk Joined Birthday Delta Random_Walk 08-12 08-13 1 snowcrash 03-29 03-28 1 salva 04-09 04-11 2 BazB 11-26 11-24 2 tekniko 05-18 05-21 3 leira 02-13 02-09 4 ejf 08-22 08-26 4 LostS 04-03 04-07 4 bassplayer 03-04 02-27 5 katgirl 08-30 08-25 5 bibo 03-31 04-05 5 cacharbe 04-03 03-29 5 arhuman 01-20 01-26 6 chicks 04-20 04-14 6 monsieur_champs 05-26 05-20 6 thunders 09-24 10-01 7 hattmoward 04-08 04-01 7 ajt 09-20 09-28 8 andreychek 04-30 04-21 9 da 05-11 05-20 9 Ven'Tatsu 06-20 06-11 9 Roger 08-29 08-19 10 Siddartha 03-28 04-07 10