Keep It Simple, Stupid | |
PerlMonks |
Re: Re: A few random questions from Learning Perl 3by Juerd (Abbot) |
on Jan 06, 2003 at 12:42 UTC ( [id://224610]=note: print w/replies, xml ) | Need Help?? |
1)Naked Blocks can be used to turn off warnings for the scope of the block - useful if you're doing some work that will encounter a lot of "uninitialized variable" warnings. Blocks are used to create scope. What you do with that scope is up to you. This kind of scope is 'lexical'. You can do a lot with it:
You don't create a block to turn off warnings. You use no warnings to turn them off. The block only limits the effect of that statement. It's important to know that the block itself has nothing to do with warnings (well, you can get warnings regarding the block of course). This lexical stuff goes for all code blocks, bare or belonging to something like if or while. Bare blocks (in this thread called 'naked blocks'; haven't seen them called that anywhere else) act like loops. In the code blocks for while, until and for, you can the use loop controlling operators next, redo and last. These can also be used with bare blocks: redo goes to the beginning of the block, last goes to the end. You cannot use loop control operators with non-loop constructs like do, if and eval. You can put a bare block in if's block to create the loop you want: Bare blocks are used like this everywhere, but often disguised: double curlies are used to make the code look nicer. So if you see doubled curly brackets, the extra block is probably only there to make breaking out of it easy.
In Section
Seekers of Perl Wisdom
|
|