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

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

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
April 29, 2008 04:15
Subject:
Re: bug in if(open(my $fh,...))
2008/4/29 John W. Krahn <krahnj@telus.net>:
>  Perl seems to think that it is closed:
>
>  $ perl -le'
>  if ( open my $fh, "<", "/etc/passwd" ) {
>     print "opened" if fileno $fh;
>     }
>  print "still opened" if fileno $fh;
>  '
>  opened
>
>
>  If it were still opened then fileno() would return true.

You're not testing the right one.

$ perl -Mstrict -le'
if ( open my $fh, "<", "/etc/passwd" ) {
   print "opened" if fileno $fh;
   }
print "still opened" if fileno $fh;
'
Global symbol "$fh" requires explicit package name at -e line 5.

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About