morgon has asked for the wisdom of the Perl Monks concerning the following question:
So far I have only used "last" in a block preceded by "for" or "while", but it seems that you can use last in any block with the effect that the remainder of the block is skipped.
So for example this works:
What would you say? Is this an acceptable (even idiomatic use of "last") or just a hack that should be avoided?if($some_condition) { open my $fh, "<", "some_file" or last; # do something with $fh here if the open was successful # if the open fails we skip this part } do_something_else();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use of last
by Eily (Monsignor) on Jul 20, 2015 at 08:20 UTC | |
|
Re: use of last
by karlgoethebier (Abbot) on Jul 20, 2015 at 08:22 UTC | |
|
Re: use of last
by Athanasius (Archbishop) on Jul 20, 2015 at 08:07 UTC | |
by morgon (Priest) on Jul 20, 2015 at 08:23 UTC | |
|
Re: use of last ( is goto, bare blocks aren't loops)
by Anonymous Monk on Jul 20, 2015 at 10:09 UTC | |
|
Re: use of last
by Anonymous Monk on Jul 20, 2015 at 16:14 UTC | |
|
Re: use of last
by james28909 (Deacon) on Jul 20, 2015 at 15:27 UTC | |
|
Re: use of last
by james28909 (Deacon) on Jul 20, 2015 at 15:27 UTC | |
by Anonymous Monk on Jul 21, 2015 at 00:18 UTC |