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:
Matt Sergeant
Date:
April 30, 2008 06:15
Subject:
Re: [perl #53504] Bug in if(open(my $fh,...)) { } scoping
Message ID:
783EACE0-3CC0-4E82-8919-457D21F9D82E@sergeant.org
On 30-Apr-08, at 7:32 AM, H. Merijn Brand via RT wrote:

>> That's exactly the opposite problem you're having there. Just remove
>> the 2nd my...
>
> 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.

Matt.

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