Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Perl Bug in Regex Code Block?

by stefan k (Curate)
on Sep 03, 2001 at 16:53 UTC ( #109857=note: print w/replies, xml ) Need Help??

in reply to Perl Bug in Regex Code Block?

not that I fully understand what you're doing there, but it seems to me that you're fiddling with scopes in a very unintuitive way (at least to me). What is the scope of counts whenever you're referring to it? Within the regexp it should be the global one, shouldn't it? It is first used outside the for-loop; but OTOH it isn't declared using my, so how could it pass use strict??
Well then, running the same code under 5.6.0/Linux results in:
Name "main::counts" used only once: possible typo at ./ line + 20. 0: 12; @counts = (0) 1: 34; @counts = (0) 2: 56; @counts = (0) @main::counts = (6)
Then uncommenting the pattern line (your third example) yields exactly the same results. Changing my to our I get the same result as you get.
You're simply throwing away the warning we get in line 20. Is this a clever thing to do?


You know what? I'm even more confused than before I started studying the code. At least I could present another results from another perl version as you wished.

Regards... Stefan
you begin bashing the string with a +42 regexp of confusion

Replies are listed 'Best First'.
Re2: Perl Bug in Regex Code Block?
by Hofmator (Curate) on Sep 03, 2001 at 17:32 UTC

    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 ./ 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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2019-05-20 01:37 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (123 votes). Check out past polls.