Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: A few random questions from Learning Perl 3

by Paladin (Vicar)
on Jan 06, 2003 at 04:48 UTC ( [id://224541]=note: print w/replies, xml ) Need Help??


in reply to A few random questions from Learning Perl 3

Congrats on your continuted progress to Sainthood. :)

1) A naked block can be used for various things. One of the more common is to limit the scope of variables. ie:

{ my $tempvar = somefunc(); # do something with $tempvar } # $tempvar no longer exists here.
or it's used to limit the scope of local()
{ local(*INPUT, $/); open (INPUT, $file) || die "can't open $file: $!"; $var = <INPUT>; } # $/ is set back to it's original value here.

2) Without knowing what you were doing with the regex, it is hard to say how it may have been wrong.

3) next goes to the next interation of the loop, not the last one. In effect it skips the rest of the current iteration (although it does execute the continue block if you have one). One common use is for skipping certian lines while reading a file.

while (<FH>) { next if /^#/; # Skip comments # now do something with $_ }
Update: Fix explaination of next

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-24 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found