<?xml version="1.0" encoding="windows-1252"?>
<node id="1002982" title="a hash and 2 loops--not working" created="2012-11-08 16:07:21" updated="2012-11-08 16:07:21">
<type id="115">
perlquestion</type>
<author id="997158">
jhumphreys</author>
<data>
<field name="doctext">
&lt;p&gt;Wise Monks-&lt;/p&gt;
&lt;p&gt;Am trying to write a currency conversion script that prompts successively until it obtains both "from" and "to" currencies that are within a hash. Not working, lol. Your advice is sought. Thanks much in advance.&lt;/p&gt;
&lt;code&gt;
#!/usr/bin/perl
# convert3.pl
use warnings;
use strict;

my ($value, $from, $to, $rate, $rates, %rates);
%rates = (
	pounds          =&gt; 1,
	USD             =&gt; 1.6,
	marks           =&gt; 3.0,
	"french francs" =&gt; 10.0,
	yen             =&gt; 174.8,
	"swiss francs"  =&gt; 2.43,
	drachma         =&gt; 492.3,
	euro            =&gt; 1.5
);
print "Enter your starting currency: ";
OUTER0: while (&lt;STDIN&gt;) {
	chomp;
INNER0: for $from (%rates) {
	last OUTER0 if $from eq $_;
	}
}
print "Enter your target currency: ";
OUTER1: while (&lt;STDIN&gt;) {
	chomp;
INNER1: for $to (%rates) {
	last OUTER1 if $to eq $_;
        }
}
print "Enter your amount to convert: ";
$value = &lt;STDIN&gt;;
$rate = $rates{$to} / $rates{$from};
print "$value $from is ",$value*$rate," $to. \n";
&lt;/code&gt; </field>
</data>
</node>
