|Perl Monk, Perl Meditation|
Re: Re: Re: Re: Regex Capturing: Is this a bug or a feature?by krusty (Hermit)
|on Sep 29, 2002 at 02:45 UTC||Need Help??|
I'd like to change "the outher block" to "an outer (imaginary) block". The outer block I used above isn't written by the coder.
Seems a funky way to state it, but what I think you're getting at is that if a local variable isn't declared within any existing block, then it will treat the current file as a block.
While it is true that the compilation unit itself (as in file or eval statement) can be the scope of a my'd (lexical) or local (dynamic) variable, that's not what's going on here.
What's declared in that block? Something is declared for the block rather than in it.
The first opening curly brace to the closing curly brace of a "for" loop is a block. Same thing with "foreach"... (for/foreach are synonyms)
Perfectly valid block...
Finally, what's wrong with this: local ($1, $2) = ($1, $2); # OK, so you can't actually write this.
Try it... It works.
What you can't do is this:
With warnings turned on you'll get something along the lines of a "modification of read-only value at line x". Update: Forget the warnings thing... $1 = 50; is a flat out compilation error