<?xml version="1.0" encoding="windows-1252"?>
<node id="1002989" title="Re: a hash and 2 loops--not working" created="2012-11-08 16:30:05" updated="2012-11-08 16:30:05">
<type id="11">
note</type>
<author id="971084">
frozenwithjoy</author>
<data>
<field name="doctext">
The main problem is that you are never actually setting the values for &lt;c&gt;$to&lt;/c&gt; and &lt;c&gt;$from&lt;/c&gt;. Below, I've made a couple changes to your script so that these values are set. Also, I made a couple other changes, including adding a note so that the user gets a prompt when entering an unrecognized currency and chomping &lt;c&gt;$value&lt;/c&gt; so that the formatting of the output looks as you wanted it to.

&lt;c&gt;
#!/usr/bin/env 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 my $cur (keys %rates) { # added keys so you don't loop through values, too
        $from = $cur; # set $from currency
        last OUTER0 if $from eq $_;
    }
    print "Currency not recognized, try again: "; # Added to avoid confusion when an unknown currency is entered
}
print "Enter your target currency: ";
OUTER1: while (&lt;STDIN&gt;) {
    chomp;
  INNER1: for my $cur (keys %rates) { # added keys so you don't loop through values, too
        $to = $cur; # set $to currency
        last OUTER1 if $to eq $_;
    }
    print "Currency not recognized, try again: "; # Added to avoid confusion when an unknown currency is entered
}
print "Enter your amount to convert: ";
$value = &lt;STDIN&gt;;
chomp $value; # added to fix format of output
$rate  = $rates{$to} / $rates{$from};
print "$value $from is ", $value * $rate, " $to. \n";

__END__
Enter your starting currency: french francs
Enter your target currency: swiss francs
Enter your amount to convert: 100
100 french francs is 24.3 swiss francs.
&lt;/c&gt;</field>
<field name="root_node">
1002982</field>
<field name="parent_node">
1002982</field>
</data>
</node>
