in reply to Hash problem: each() failure
To add to the already great comments made...
When you initialize a hash it is standard convention to use '=>' between key/value pairs rather than commas...
e.g. {'P' =>'a','N' =>'b','U' =>'c'}
it is strictly a readability thing, but since code is written for people, readability is everything
Since a hash is just a "special" array, it may be easier to understand the problem by looking at an array example.
If you initialiaze an array with square brackets you get a reference to the array.
On the other hand, if you initialize with parentheses
@x = ('P','a','N','b','U','c');
you will get the actual array.
Creating the hash with the {} braces works like the square brackets on an array.
Another great comment made was to suggest you should enable warnings on your code. I cannot agree more. You should just get in the automatic habit of adding strict and warnings to everything you write. e.g.
#!/usr/bin/perl
use strict;
use warnings;
my 2 bits...
Anyone know how to get square brackets to show up in my source listing on the perl monks site?