in reply to Re: "my $filehandle" scoping strange problem
in thread "my $filehandle" scoping strange problem

Given, as you said, $fh is scoped to the unless block, why the almighty DWIMery allows to use $fh afterwards within a scope of use strict;??

Replies are listed 'Best First'.
Re^3: "my $filehandle" scoping strange problem
by Fletch (Bishop) on Apr 14, 2006 at 13:30 UTC

    It doesn't. Add a -Mstrict or use strict; and it complains.

    $ perl -MO=Deparse,-p,-q use strict; open my $fh, "<f1.txt" or do { print STDERR "can't open <f1.txt, but nevermind, I'll try f2.txt\n +"; open $fh, "<f2.txt" or die "still can't..."; }; print <$fh>; ^D Global symbol "$fh" requires explicit package name at - line 5. - had compilation errors. use strict 'refs'; unless (open(my $fh, '<f1.txt')) { do { print(STDERR "can't open <f1.txt, but nevermind, I'll try f2.t +xt\n"); (open(${'fh'}, '<f2.txt') or die(q[still can't...])); }; } print(<$fh>);
      Thanks.

      Actually my problem was due to yet another $fh in outer block.
      My larger script, which uses strict (let strict's days will be countless:) contained another declaration of $fh, so within open my $fh ...... outer $fh come into play .....

      Problem is solved...