6 Apr 2006 18:42
Re: [QUIZ] Perl 'Easy' Quiz of the Week #2006-04-02 - Rounded Fractions
Here's my solution:
#!/usr/bin/perl
use strict;
use warnings;
eval {
main ();
};
if ( my $err = $ <at> ) {
print STDERR "# $0: $err\n";
exit 1 ;
}
exit 0;
sub main {
my $in_frac1 = shift <at> ARGV or die "need two inputs";
my $in_frac2 = shift <at> ARGV or die "need two inputs";
my $dec1 = frac2dec( $in_frac1 );
my $dec2 = frac2dec( $in_frac2 );
my $frac = dec2frac( $dec1 * $dec2 );
print "$in_frac1 X $in_frac2 = $frac\n",
"$dec1 X $dec2 = ", $dec1 * $dec2, "\n";
}
sub dec2frac {
my $dec = shift () or die "no input in dec2frac";
(Continue reading)
RSS Feed