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,...))
Message ID:
b77c1dce0804290415i3ef3b235q458fc8d931512e87@mail.gmail.com
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About