On Wed, 2002-05-01 at 18:47, Damien Neil wrote:
> On Wednesday, May 1, 2002, at 02:27 PM, Aaron Sherman wrote:
> > unless my $fh = $x.open {
> > die "Cannot open $x: $!";
> > } else while $fh.getline -> $_ {
> > print;
> > } else {
> > die "No lines to read in $x";
> > }
>
> I think you need a better example--given that the unless clause throws
> an exception, the "else while" can just as easily be written as a
> "while", no "else". (Which I, personally, would find far clearer.)
No, I write this sort of thing all the time:
if (foo) {
die $!
} else {
stuff
}
It's clearer, IMHO, to the reader and maintainer of the code, exactly
what is expected. It's taste and style and visual aesthetics, but we
wouldn't have a postfix "if" if those things didn't matter in Perl.