OK, to your first problem

It [@counts] is first used outside the for-loop
this is inside a single quoted string. It is the same as if I put it directly into the regex in the loop or declare it inside the loop. The reason I'm doing it this way is that I want to change this pattern inside the loop for my third testcase.

Name "main::counts" used only once: possible typo at ./re-code.pl line + 20. 0: 12; @counts = (0) 1: 34; @counts = (0) 2: 56; @counts = (0) @main::counts = (6)
This is very interesting. As I interpret it, the code block inside the regex uses the global variable @main::counts which is otherwise blocked from view inside the loop by the my @counts declaration. A simple equivalent example
{ my $num = 0; $main::num = 5; # this instead of the regex print $num; # prints 0 } print $num; # prints 5 # or under use strict print $main::num; # prints 5 as well
Makes perfect sense. However with 5.6.1 you seem to be able to use lexical variables from the enclosing scope, but this is where the bug comes in. It works the first time but doesn't work the next times.

btw, the warning can be ignored in this case

-- Hofmator


In reply to Re2: Perl Bug in Regex Code Block? by Hofmator
in thread Perl Bug in Regex Code Block? by Hofmator

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.