I am just starting to learn Perl using the book Beginning Perl by Simon
Cozens.
http://learn.perl.org/library/beginning_perl/

In ch 4 pg 3, there is a program in which I am to create a currency
converter. I start by creating a hash with various currencies and their
relative values. I use <STDIN> to enter my country of origin, destination
country, and the amount of my native currency. Then I write two formulas
to calculate the value of my native currency in my destination country.

my ($value, $from, $to, $rate, %rates);
%rates=(
        pounds => 1,
        dollars => 1.6,
        marks => 3.0,
        "french francs" => 10.0,
        yen => 174.8,
        "swiss francs" =>2.43,
        drachma => 492.3,
        euro =>1.5
        );

print "Enter your starting currency: ";
$from = <STDIN>;
print "Enter your target currency: ";
$to = <STDIN>;
print "Enter your amount: ";
$value = <STDIN>;

chomp($from,$to,$value);
$rate = $rates{$to} / $rates{from};

print "$value $from is", $value*$rate," $to.\n";

In the book, running the program returns the following (using * .* to
indicate inputed values):
Enter your starting currency: *dollars*
Enter your target currency: *euro*
Enter your amount: *200*
200 dollars is 187.5 euro.
>

However, when I run the program, I get:
Enter your starting currency: *dollars*
Enter your target currency: *euro*
Enter your amount: *200*
Use of uninitialized value in division (/) at convert1.plx line 26,
<STDIN> line 3.
Illegal division by zero at convert1.plx line 26, <STDIN> line 3.

There appears to be a problem in how <STDIN> retuns hash values in my
version 5.8 that is not present in the author's version. Any suggestions?

Thankfully,
Joe


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to