Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Weird hash access problem

by kennethk (Abbot)
on May 26, 2011 at 18:30 UTC ( [id://906873]=note: print w/replies, xml ) Need Help??


in reply to Weird hash access problem

$1 does not contain what you think it does. If you modify your code to wrap your output in a delimiter:
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"
you get:
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])/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://906873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-20 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found