Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Perl Bug in Regex Code Block?

by MZSanford (Curate)
on Sep 03, 2001 at 16:38 UTC ( #109852=note: print w/replies, xml ) Need Help??


in reply to Perl Bug in Regex Code Block?

I may be confussed, but i think the problem is with the :
my @counts = (0);
... specifically, the my. When you use my, you are creating a variable which will disappear when it goes out of scope. since the for (0..2) {} loop is the current scope, when it completes, @counts is destroyed. This is fixed by not using a my inside of the for loop (as you have seen), and is a very perlish thing.
can't sleep clowns will eat me
-- MZSanford

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

    When you use my, you are creating a variable which will disappear when it goes out of scope.
    I'm well aware of that ... but the regex is taking place inside this scope and so the lexical variables should be accessible inside the regex. This works the first time as expected but it doesn't work on the second and third iteration of the loop.

    Maybe you have misunderstood my question, I'm not confused that the last line of my code doesn't print anything. It was only included for the (working) run with our instead of my. I want to know, why it's changing its behaviour inside the loop.

    I hope this clarifies my problem ...

    -- Hofmator

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2019-07-17 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?