http://www.perlmonks.org?node_id=615742

OK, so it's not terribly unique, but I thought it was a bit of fun. The background (and the explanation of some odd bits) is at my personal blog. I wrote this because I was curious about my weight on the new Earth which was discovered. The program takes your current weight (in any units) as an argument. Defaults to my weight :)

#!/usr/bin/perl use strict; use warnings; my $weight = shift || 189; # you can manually change the weight here, + if you prefer # for simplicity's sake, we assume Audrey and Johnny are spherical my @data = ( # body mass in kg radius in km [ 'Mercury', 3.302 * 10**23, 2439.7 ], [ 'Venus', 4.8685 * 10**24, 6051.9 ], [ 'Earth', 5.9736 * 10**24, 6378.137 ], [ 'Moon', 7.3477 * 10**22, 1748.14 ], [ 'Mars', 6.4185 * 10**23, 3402.5 ], [ 'Ceres', 9.46 * 10**20, 950 ], # rough es +timates [ 'Jupiter', 1.8986 * 10**27, 71492 ], [ 'Saturn', 5.6846 * 10**26, 60286 ], [ 'Uranus', 8.6832 * 10**25, 25559 ], [ 'Neptune', 10.243 * 10**25, 24764 ], [ 'Pluto', 1.305 * 10**22, 1195 ], # rough es +timates [ 'Eris', 1.6 * 10**22, 1200 ], # rough es +timates [ 'Audrey Hepburn', 49.8951607, 0.0017018 ], [ 'Johnny Depp', 70.3068174, 0.001778 ], ); my ( %mass_of, %radius_of ); foreach my $data (@data) { my $body = $data->[0]; $mass_of{$body} = $data->[1]; $radius_of{$body} = $data->[2]; } $mass_of{Hope} = 5 * $mass_of{Earth}; $radius_of{Hope} = 1.5 * $radius_of{Earth}; $mass_of{'Heavy Earth'} = 2 * $mass_of{Earth}; $radius_of{'Heavy Earth'} = $radius_of{Earth}; $mass_of{'Fat Earth'} = $mass_of{Earth}; $radius_of{'Fat Earth'} = 2 * $radius_of{Earth}; print "If you weighed $weight units ...\n"; foreach my $body ( map( { $_->[0] } @data ), 'Hope', 'Heavy Earth', 'F +at Earth' ) { printf "... you would weigh %.2f units on '$body'\n" => weight_on( +$body); } sub weight_on { my $body = shift; return $weight * ( gravity($body) / gravity('Earth') ); } sub gravity { my $body = shift; return density($body) * $radius_of{$body}; } sub density { my $body = shift; return $mass_of{$body} / $radius_of{$body}**3; }

Cheers,
Ovid

New address of my CGI Course.