I am reading a doc I found online about Perl, I am learning it for a project, and I was studying code that converts currency. The code:
#!/usr/bin/perl
use warnings;
use strict;
my ($number_to_convert, $first_currency, $second_currency, $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 first currency: ";
$first_currency = <>;
print "Enter second currency: ";
$second_currency = <>;
print "Enter amount you wish to convert from ", $first_currency, " to ", $second_currency, "\n";
$number_to_convert = <>;
chomp($first_currency,$second_currency,$number_to_convert);
#Line 23 is a convinience measure, not mandatory
$rate = $rates{$second_currency} / $rates{$first_currency};
print $number_to_convert," ",$first_currency," is ",$number_to_convert*$rate," ",$second_currency, "\n";
What I had a question about was this line:
$rate = $rates{$second_currency} / $rates{$first_currency};
What I understand is that the hash called "rate" takes the second currency entered by the user and divides it by the first currency entered by the user. I wanted clarification on if this is how you would verify that what the user typed in was from the hash, how Perl knows what 2 currencies the uesr is converting, and [ANSWERED SEE EDIT]how I could tell the user that what they entered was not recognized (say if they misspelled "dollars" or something)[ANSWERED SEE EDIT]. Also, would the syntax be the same for strings and numbers?
EDIT:
Upon further reading my question about the misspelling was answered, however I have another question. How do you divide a string by a string?