in reply to {} vs do{}
If you want to use the return value, then you want to use do:
If you want to use loop control, then you have to use a bare block. merlyn gives some ideas at RE: My favorite looping mechanism in Perl is: about why you might want to do that.# Trick for generating a symbol to use as, for instance, # a filehandle... my $fh = do {local *FH};
If you want to put several statements where syntactically only one is supposed to go, you would want do. That might look like this:
Note that I don't feel the need for this use of do. So I will follow up with a use for bare blocks that I feel is equally useless. Suppose you don't like semi-colons. Well help is at hand!do {print "Hello"; print " World\n";} for 1..10;
Does that clarify the similarities and differences?{print "Hello"} {print " World\n"} # etc
|
|---|