Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Happy unbirthday! (To all, with a challenge)

by Not_a_Number (Parson)
on Sep 27, 2011 at 12:03 UTC ( #928074=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Happy unbirthday! (To all, with a challenge)
in thread Happy unbirthday!

I found a a couple of bugs in your code.

First, when I use it today, it prints "Happy 22,023nd unbirthday, dave!" Change the antepenultimate line to:

my $unbirthdays = commify( ORD($days_alive - $birthdays));

Second, if somebody types in "October" for their month of birth, they'll be surprised to see "Sorry, this is not a month"! Change the line:

if ($b_month =~ /0/) {

to:

if ($b_month != 0) {

In fact, I would refactor that bit of code to avoid the programme dying ungraciously if the user enters a non-alphanummeric character:

if ($b_month !~ /^\d+$/) { $b_month = Decode_Month($b_month,1); } if (! $b_month) { print "Sorry, that is not a month.\n"; $b_month = birth_month(); }

Lastly, a minor niggle: 1900, for example, was not a leap year, despite being divisible by 4.

Update: You also seem to have an off-by-one error. If I claim to have been born today, the output is:

Happy 0th unbirthday, dave!

Surely, today should be by first (not 0th) unbirthday?


Comment on Re^3: Happy unbirthday! (To all, with a challenge)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928074]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2015-07-06 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (71 votes), past polls