Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: A few random questions from Learning Perl 3

by theorbtwo (Prior)
on Jan 06, 2003 at 04:56 UTC ( #224545=note: print w/replies, xml ) Need Help??


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:

while (1) { print "a"; next; print "b"; next; exit; }
will keep printing "a" over and over, and never get to the second next. It's still perfectly valid code... just not very useful.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-02-25 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (113 votes). Check out past polls.

    Notices?