in reply to What is wrong with my calculations?

Here are a few other pointers:
# Save some typing when you can! Make your vars lexical where it make +s sense. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ +tomorrows_time); # Get the last two digits. Much cleaner and faster $year = substr($year,-2,2); # I like to use a variable to turn on/off the debug code my $debug = 1; # somewhere near the top print "Testing: $important_currencies{$abbrev}" if $debug; # It's SO EASY to check for a zero in your divisor, so don't pass up t +he free ride! :) my $newrate; if (!$second_currency) { print "HEY! Don't divide! You'll puke!\n"; } else { $newrate = ($first_currency / $second_currency); }
Here's my own version of the code. I liked the problem, so I played around with it a bit. Hopefully it has a few tasty tidbits that will help you out with future homework assignments.. erm, programming dilemmas. :) It looks like you put in some good thought and effort into your code, so I'm happy to help out!
my $tomorrows_time = time() + 86400; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ +tomorrows_time); my $month_name=('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP', +'OCT','NOV','DEC')[$mon]; $year = substr($year,-2,2); $mday = sprintf("%02d", $mday); my $date_stamp = "$mday-$month_name-$year"; my %conversions = ( 'AUD' => qq(USD), 'CAD' => qq(USD), 'DEM' => qq(USD), 'FRF' => qq(USD GBP), 'GBP' => qq(USD), 'JPY' => qq(USD), 'NZD' => qq(USD), 'NLG' => qq(USD), 'DEM' => qq(GBP), 'EUR' => qq(USD GBP), 'NZD' => qq(AUD), 'ESP' => qq(GBP), ); my %currencies = ( 'USD' => { 'usd_equiv' => 1, 'currency_per_usd' => 1, } ); foreach (<DATA>) { my ($country,$abbrev,$usd_equiv,$currency_per_usd) = split /,/; next unless $usd_equiv && $currency_per_usd; $currencies{$abbrev}{usd_equiv} = $usd_equiv; $currencies{$abbrev}{currency_per_usd} = $currency_per_usd; } foreach my $currency (keys %conversions) { foreach my $comp_currency (split /\W+/, $conversions{$currency}) { print qq($currency,$comp_currency,$date_stamp,$date_stamp,); print sprintf("%f\n", ($currencies{$currency}{'usd_equiv'} / $ +currencies{$comp_currency}{'usd_equiv'})); } } __DATA__ Australian (Dollar),AUD,0.5295,1.8896 Canadian (Dollar),CAD,0.6295,1.5888 German (Mark),DEM,0.8794,1.1375 Spanish (Peseta),ESP,0.8794,1.1375 Euro,EUR,0.8794,1.1375 French (Franc),FRF,0.8794,1.1375 British (Pound),GBP,1.4316,0.6987 Hong Kong(Dollar),HKD,0.1282,7.7997 Italian (Lira),ITL,0.8794,1.1375 Japanese (Yen),JPY,0.007592,131.73 Dutch (Guilder),NLG,0.8794,1.1375 New Zealand (Dollar),NZD,0.4375,2.2883