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

Re: bug in if(open(my $fh,...))

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
April 28, 2008 13:40
Subject:
Re: bug in if(open(my $fh,...))
Message ID:
20080428204010.GO10938@iabyn.com
On Mon, Apr 28, 2008 at 07:53:07PM +0000, Matt Sergeant wrote:
> Oh interesting. So it's specific to if() blocks. That's a huge relief and I 
> consider it way less of a showstopper - I thought the file was remaining 
> open until END{}.


More precisely, the bug is a mismatch between compile-time and run-time
scopes.

In the following:

    {
	if (my $x = ...) {
	    ..
	}
	else {
	    ...
	}
	X
    }
    Y

At point X, at compile time, $x is no longer in scope; any mention of $x
refers to an outer $x (or $::x).

At run time, $x has not been freed yet, and wont be until the next scope
is exited (ie just before Y)

Adding the extra scope exit op could be done only when the if includes a
my, avoiding the slowdown on the general case.



-- 
You never really learn to swear until you learn to drive.

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