Syntactic Confectionery Delight | |
PerlMonks |
Re: rough approximation to pattern matching using localby BrowserUk (Patriarch) |
on Jan 25, 2015 at 12:58 UTC ( [id://1114431]=note: print w/replies, xml ) | Need Help?? |
It is clear that you are expecting match() to construct a variable called $bob, give it the value 45; in such a way that when the anonymous subroutine that is the third argument is run, that variable will exist and be visible to that subroutine. What isn't clear is quite how what you are doing would achieve that goal. A simple diagnostic run just before you invoke the anonymous sub:
Shows that what you've done is add a key:bob with the value 45 to the hash(ref) name $locals:
What that also shows is that the first warning:Name "main::bob" used only once: is produced at compile time; ie. long before your code ever gets invoked; so nothing your code does at runtime will resolve the problem you are being warned about. I think that's because the while loop localizes each variable only within the body of the loop. Indeed. Everything you did with local is undone as soon as you leave the body of the loop. In order to achieve your goal -- the declaration and initialisation of variables either within the scope of, or closed over by, your anonymous subroutine -- you would have to be modifying the symbol table prior to that anonymous subroutines compilation! Ie. You'd have to do something before your code was run. And that a tall order unless your code is running within the compiler itself. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
In Section
Seekers of Perl Wisdom
|
|