in reply to Weird hash access problem
you get: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 "x$h{$1}x\n"; #print nothing print "x$h{a1}x\n"; #print 1 print "x$1x\n"; #print "a1"
test work xx x1x xa1 x
You are grabbing whitespace in addition to your square id. You'll get your expected result if you modify your regular expression to:
/([a-hA-H][1-8])\s*to\s*([a-hA-H][1-8])/
|
|---|