#!/usr/bin/perl
# --------------- exchange.pl -----------------
&read_exchange_rate; # read exchange rate into memory
# now let's cycle, asking the user for input...
print "Please enter the amount, appending the first letter of the name of\n";
print "the currency that you're using (franc, yen, deutschmark, pound) -\n";
print "the default value is US dollars.\n\n";
print "Amount: ";
while (<STDIN>) {
($amnt,$curr) = &breakdown(chop($_));
$baseval = $amnt * (1/$rateof{$curr});
printf("%2.2f USD, ", $baseval * $rateof{'U'});
printf("%2.2f Franc, ", $baseval * $rateof{'F'});
printf("%2.2f DM, ", $baseval * $rateof{'D'});
printf("%2.2f Yen, and ", $baseval * $rateof{'Y'});
printf("%2.2f Pound\n\nAmount: ", $baseval * $rateof{'P'});
}
sub breakdown {
@line = split(" ", $_);
$amnt = $line[0];
if ($#line == 1) {
$curr = $line[1];
$curr =~ tr/a-z/A-Z/; # uppercase
$curr = substr($curr, 0, 1); # first char only
} else { $curr = "U"; }
return ($amnt, $curr);
}
sub read_exchange_rate {
open(EXCHRATES, "
#!/bin/sh
# --------------- build-exchrate.sh -----------------
# Build a new exchange rate database by using the data on Yahoo
# special case for the british pound needed...
lynx -dump http://quote.yahoo.com/m3\?u | \
awk '/U.K./ { if (NF > 4) print "P\t"$3 }'
# now let's get the other three...
lynx -dump http://quote.yahoo.com/m3\?u | \
awk '/Can/,/SFran/ { if (NF > 4) print $1"\t"$2 }' | \
cat -v | sed 's/M-%/Y/' | \
egrep '(U.K.|DMark|FFranc|Yen)' | \
sed 's/U.K./P/;s/DMark/D/;s/FFranc/F/;s/Yen/Y/'
echo "U 1"
echo ""
echo "# data extracted from quote.yahoo.com on `date`"
exit 0
(use your mouse to select everything between the two lines,
then save the selection to your disk, or just
click here to download them in ZIP archive
format)