The 2004 Perl Advent Calendar
[about] | [archives] | [contact] | [home]

On the 18th day of Advent my True Language brought to me..

So, I can just imagine the people sitting at home clicking on the advent calendar today, then with frowns on their face realising that the lazy so and so that runs the site hasn't updated the page yet. In the grand tradition of MegaTokyo I'm having a "Dead Mark Day".

Of course, it would have all been better if I'd paid more attention to what I was drinking last night at the Christmas Karoke. I should have worked out just how drunk I was going to get. I needed Acme::Drunk.

Acme::Drunk can be used to calculate the blood alcohol concentration in a human. Let's look at the example from the documentation:

  use Acme::Drunk;
  my $bac = drunk(
     gender         => MALE, # or FEMALE
     hours          => 2,    # since start of binge
     body_weight    => 160,  # in lbs
     alcohol_weight => 3,    # oz of alcohol
  if ($bac >= 0.08) { call_cab() } else { walk_home() }

So, to work out exactly what I had to drink last night, let's work out what was going on. Right, what did I drink last night:

  one bottle of stella (330ml) 
  a quarter a can of Heineken Export (about 75ml)
  three UK pints of Adnams (1704ml)

Oh dear oh dear. Let's look at this programmatically:

  # define the constants
  use constant FLOZ_PER_ML => 0.0338140226;
  use constant PERCENTAGE  => 0.05;
  # convert the values to fl oz and then work out the percentage
  my $stella =  330 * FLOZ_PERL_ML * PERCENTAGE;
  my $export =   75 * FLOZ_PERL_ML * PERCENTAGE;
  my $adnams = 1704 * FLOZ_PERL_ML * PERCENTAGE;
  my $total = $stella + $export + $adnams;

Now we have to work out my weight. I'm about 11 stone (stop sniggering at the back - I am.)

  use constant LBS_PER_STONE => 14;
  my $weight = 11 * LBS_PER_STONE;

Luckly, I started at 4.30pm (don't ask) and then completed drinking at 11pm (pub closing time.) That's six and a half hours. We now have enough to calculate my blood alcohol concentration last night.

 use Acme::Drunk;
 print drunk(
   gender         => MALE,
   hours          => 6.5,
   body_weight    => $weight,
   alcohol_weight => $total,
 ), "\n";

Which prints out:


Hmm. Looks like I wasn't actually that drunk. Darn, that means I've got to come up with a better excuse.

  • MegaTokyo cartoon