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:
H.Merijn Brand
Date:
April 29, 2008 21:08
Subject:
Re: [perl #53504] Bug in if(open(my $fh,...)) { } scoping
Message ID:
20080429144239.373f8faf@pc09.procura.nl
On Mon, 28 Apr 2008 23:57:01 -0700, Matt Sergeant (via RT)
<perlbug-followup@perl.org> wrote:

> # New Ticket Created by  Matt Sergeant 
> # Please include the string:  [perl #53504]
> # in the subject line of all future correspondence about this issue. 
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=53504 >
> 
> 
> The following code:
> 
>    if (open(my $fh, "/etc/passwd")) {
>      ...
>    }
> 
> Leaves the file open at the exit of the scope (in fact to the end of  
> the program). But $fh is out of scope, meaning the file should be  
> closed.

related nuisance:

/home/merijn 102 > cat xx.pl
#!/pro/bin/perl

use strict;
use warnings;

if    (my @scr = glob ("*.sh")) {
    print "I have shell scripts here\n";
    }
elsif (my @scr = glob ("*.pl")) {
    print "I have perl scripts here\n";
    }
/home/merijn 103 > perl xx.pl
"my" variable @scr masks earlier declaration in same scope at xx.pl line 9.
I have perl scripts here
/home/merijn 104 >


-- 
H.Merijn Brand         Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.10.x  on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.1 & 10.2, AIX 5.2, and Cygwin.       http://qa.perl.org
http://mirrors.develooper.com/hpux/            http://www.test-smoke.org
                        http://www.goldmark.org/jeff/stupid-disclaimers/

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