Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re2: Perl Bug in Regex Code Block?

by Hofmator (Curate)
on Sep 03, 2001 at 20:07 UTC ( #109885=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Bug in Regex Code Block?
in thread Perl Bug in Regex Code Block?

Some answers to your questions

  • Concerning the error message in connection with the last print statement ... I cannot reproduce that, it works fine both ways (commented and uncommented). With strict and warnings I get
    Possible unintended interpolation of @counts in string at bug line 20. Global symbol "@counts" requires explicit package name at bug line 19. Global symbol "@counts" requires explicit package name at bug line 20.
    and it dies as expected. Adding the explicit @main:: solves the problem altogether.
  • And I have another point of weirdness to note in the regex you are using you have placed a '^' caret at the END of the regex
    This is weirdness, you are right and actually not necessary for the thing in question here. It is a left-over from the code where I originally encountered the problem. But I can explain the behaviour ... consider this simpler regex "ab" =~ /.^/;
    it matches any character and after that the beginning of the line, so it can never match! Nevertheless the regex tries to match. First the a, then it sees that that doesn't work out and so tries the b after which it fails. If we now sneak in a code block like this "ab" =~ /.(?{print 'hello!'})/;
    the regex passes this block twice! And you can do very nice things with that (see e.g. my twiddle code) ... the original code came from a nonogram solver which I will post here in a couple of weeks (I have to find time to clean up the code a bit :)

Update: I forgot to mention use re 'debug'. It is always helpful when you don't understand a pattern match.

-- Hofmator

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2019-05-22 06:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (138 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!