質問をするとマイナスポイントになるリスクがありますが、Perl インタープリターが検出したエラーについて助けを求めています。これはBeginning Perlの宿題です。
Q: 通貨プログラムを修正して、有効な通貨名が入力されるまで通貨名を尋ね続けるようにします。
#! /usr/bin/perl
#convert.pl
use warnings;
use strict;
my ($value, $from, $to, $rate, %rates);
%rates = (
pounds => 1,
dollars => 1.6,
marks => 3,
"french frances" => 10,
yen => 174.8,
"swiss frances" => 2.43,
drachma => 492.3,
euro => 1.5
);
print "currency exchange formula -
pounds, dollars, marks, french frances,
yen, swiss frances, drachma, euro\n";
print "Enter your starting currency: ";
$from = <>;
chomp($from);
While ($from ne $rates{$from}) {
print "I don't know anything about $from as a currency\n";
print "Please re-enter your starting currency:";
$from = <>;
chomp($from);
}
print "Enter your target currency: ";
$to =<>;
chomp($to) ;
While ($to ne $rates{$to}) {
print "I don't know anything about $to as a currency\n";
print "Please re-enter your target currency:";
$to = <>;
chomp($to);
}
print "Enter your amount: ";
$value = <>;
chomp ($value);
if ($value == 0) {
print "Please enter a non-zero value";
$value = <>;
chomp ($value);
}
$rate = $rates{$to} / $rates{$from};
print "$value $from is ", $value*$rate, " $to.\n";
4 つのエラーが特定されました。すべてがor ... などのwhile
ループ内にあります。たとえば27 行目などにあるのは、との間の空白だけです。私が見る限り、著者によって提供されたソリューションは、著者が使用することを除いて、私のスクリプトとほぼ同じです。「ね」の使い方を誤解していませんか?または、私のスクリプトに何か問題がありますか? どうもありがとう。"syntax error at line 27, near ") {"
...at line 33, near "}"
")"
"{"
while (not exists $rates{$from}) { ... }