unless (open(FILE,">temp")) {
This is fine and dandy. I used to prefer it. But, it should come with a caveat... If you like to autovivify your filehandles, using that construct might cause a problem. Consider:
In that code, $fh is lexical to the unless block. That probably isn't what you want because you only enter the block if the open fails. This pitfall may be more likely to come up when changing existing code than when writing new code altogether.unless (open my $fh, '<', 'file') { # . . . }
You can get around it by declaring $fh prior to the unless but, now anyway, I prefer to avoid it by using
instead. That also puts the emphasis back on the open statement itself.open my $fh, '<', 'file' or do { # . . . };
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Question about warn statement
by sauoq
in thread Question about warn statement
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |