in reply to Re^2: "my $filehandle" scoping strange problem
in thread "my $filehandle" scoping strange problem
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>);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: "my $filehandle" scoping strange problem
by vkon (Curate) on Apr 14, 2006 at 13:54 UTC |