develooper Front page | perl.perl5.porters | Postings from April 2008

Re: [perl #53504] Bug in if(open(my $fh,...)) { } scoping

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
April 30, 2008 07:04
Subject:
Re: [perl #53504] Bug in if(open(my $fh,...)) { } scoping
Message ID:
b77c1dce0804300703o3af21960yd785f4849e2110ef@mail.gmail.com
2008/4/30 Matt Sergeant <matt@sergeant.org>:
> > I know. The `problem' is that the scoping doesn't DWIM. At least not
> > for me. I don't expect the 'if (my $x = ...) {}' to live on in the else
> > branch, which is why I expect the above snippet to work. I also know it
> > to not work when I see the error, and then I usually change the code to
> >
> > {   my @scr;
> >    if    (@scr = ...) {
> >        :
> >        }
> >    elsif (@scr = ...) {
> >        }
> >    }
> >
>
>  Yup, IMHO this was an error in judgement by whoever chose this behaviour
> originally. But we're stuck with it now.

I don't think so.
I think the intent behind this feature's design was to allow :

if ((my $ret = somecall()) == 0) {
    # profit !
}
elsif ($ret == -1) {
    # handle error code -1
}
elsif ($ret == -2) {
    # handle error code -2
}
else { etc... }

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About