tehjord has asked for the wisdom of the Perl Monks concerning the following question:
Hi, im making some cheap chess game, but I got a very weird problem when accessing an hash using $1 following a regex match.
The regex used works perfectly, but the problem is, when I try to access my hash table using the $1 var, it simply does not work.
Ive tried first copying $1 to a temp var and then using that temp var to access my hash but with no success.
Here is my code which should explain everything:
THX FOR THE REPLIES ! works !use strict; my %h = (a1 => 1); my $test = "a1 to a2"; if ($test =~ /([a-hA-H][1-8]\s*)to(\s*[a-hA-H][1-8])/) { print "test work\n"; } print $h{$1}; #print nothing print $h{a1}; #print 1 print $1; #print "a1"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Weird hash access problem
by toolic (Bishop) on May 26, 2011 at 18:31 UTC | |
Re: Weird hash access problem
by wind (Priest) on May 26, 2011 at 18:30 UTC | |
Re: Weird hash access problem
by kennethk (Abbot) on May 26, 2011 at 18:30 UTC | |
Re: Weird hash access problem
by ikegami (Patriarch) on May 26, 2011 at 18:32 UTC | |
Re: Weird hash access problem
by jfroebe (Parson) on May 26, 2011 at 18:32 UTC | |
by ikegami (Patriarch) on May 26, 2011 at 18:33 UTC | |
by jfroebe (Parson) on May 26, 2011 at 19:07 UTC |
Back to
Seekers of Perl Wisdom