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

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

Thread Previous | Thread Next
From:
Matt Sergeant
Date:
April 28, 2008 12:53
Subject:
Re: bug in if(open(my $fh,...))
Message ID:
alpine.DEB.1.00.0804281951390.12136@bodger.sergeant.org
On Mon, 28 Apr 2008, Bram wrote:

>>> A proper fix would be to add an "invisible" block around the if. That
>>> would slow down all ifs a bit, though.
>> 
>> I don't think that works either:
>> 
>> perl -Mstrict -le 'if (1) { if (open(my $fh, q(/etc/passwd))) { print
>> "inner"; } } system(qq(ls -l /proc/$$/fd));'
>> 
>> Shows that the filehandle just isn't closed AT ALL (until program exit).
>> 
>
> perl -Mstrict -le '{ if (open(my $fh, q(/etc/passwd))) { print "inner"; } }
> system(qq(ls -l /proc/$$/fd));'
>
> Shows that the filehandle is closed.

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{}.

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