2009/3/10 Jim Gibson <jimsgib...@gmail.com>: > On 3/10/09 Tue Mar 10, 2009 7:59 AM, "Dermot" <paik...@googlemail.com> > scribbled: > >> Hi, >> >> I am not getting the results that I expect from this test and I am not >> sure why. If I run the script below I get: >> >> 1..3 >> Line=???/FOO BAR, Name=Joe Smo M="???" >> ok 1 - handle_name ???/FOO BAR >> Line=change accordingly /FOO BAR, Name=Foo bar M="change" >> ok 2 - handle_name change accordingly /FOO BAR >> Line=GEOF KID/FOO BAR, Name=Geoff Kidd M="" >> Use of uninitialized value in concatenation (.) or string at >> credit_handle.t line 33. >> not ok 3 - handle_name GEOF KID/FOO BAR >> # Failed test 'handle_name GEOF KID/FOO BAR' >> # at credit_handle.t line 16. >> # Looks like you failed 1 test of 3. >> >> >> The 'GOOF KID' entry is not getting handled correctly (or rather as I >> want). It is being processed within the initial if() block. It was my >> understanding that a failed match would mean control would fall to the >> else statement. If I uncomment the 2 lines below, I can make it would >> but I suspect there is something I am not seeing here. I have used >> this construct a lot in the past and it's been fine. > > The match does not fail. In fact, your regex will always match any string. > One of the alternatives is equivalent to /^\?*/, which means "zero or more > question mark characters at the beginning of the string" and will always be > true. Change this to /^\?+/ meaning "one or more ..." and you should get the > results you are expecting. The alternative works because after the match $& > contains what has matched, in this case the empty string '', which evaluates > to false, even though you have actually matched your R.E.
Thanx Jim. That makes sense. I should have spotted that myself :\ Dp. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/