in reply to A few random questions from Learning Perl 3
1: Naked blocks. You can use naked blocks for quite a number of purposes. They can be used to scope (lexical/my) variables, which is what I normaly use them for. You can also use the loop control operators (next,redo,last...) on them, and build your own loop that operates exactly how /you/ want it to.
2: I can think of several reasons. One is using a m// where an eq would do -- regexes are /expensive/. Also, interpolating a variable into a regex will use the regex metachars in the interpolated variable as such, which is normaly not what you want.
3: next takes you directly to the next iteration of the loop. You can call it only once per iteration (obviously), but as many places as you want.... for example:
will keep printing "a" over and over, and never get to the second next. It's still perfectly valid code... just not very useful.while (1) { print "a"; next; print "b"; next; exit; }
|
|---|