In the following small code, I do not get an error or a warning for lines [09] and [18]. The only warning I get is with line [21]:
use strict; # [01]
use warnings FATAL => 'unopened'; # [02]
# [03]
open(my $outHandleA, ">outputA.txt") or die ("A: $!\n"); # [04] Opened $outHandleA
print $outHandleA "FILE A\n"; # [05]
close $outHandleA; # [06] Closed $outHandleA
# [07]
print $outHandleA; # [08]
print $outHandleA "ABC\n"; # [09] <---
print $outHandleA; # [10]
print "-----"; # [11]
# [12]
open(OUT, ">outputB.txt") or die ("B: $!\n"); # [13] Opened OUT
print OUT "FILE B\n"; # [14]
close OUT; # [15] Closed OUT
# [16]
print OUT; # [17]
print OUT "DEF\n"; # [18] <---
print OUT; # [19]
# [20]
print DOES_NOT_EXIST_HANDLE "GHI\n"; # [21] Raises a FATAL warning
# [22]
print "JKL"; # [23] Does not reach here (as expected)
However, shouldn't lines [09] and [18] also raise an error or a warning like the following since it is closed (unopened)?
- ERROR:
print() on closed filehandle $outHandleA at printingToClosedHandle.pl line 9.
- WARNING:
print() on unopened filehandle $outHandleA at printingToClosedHandle.pl line 9.
This might be an issue with my version of Perl which is "perl 5, version 28, subversion 1 (v5.28.1) built for MSWin32-x64-multi-thread". Furthermore, here is the output of the program I get below:
outputA.txt | outputB.txt | STDOUT |
---|---|---|
FILE A | FILE B | GLOB(0xfeb428)GLOB(0xfeb428)----- |
The STDOUT output in above table is from lines [08], [10], and [11]. Please note that the value between the parenthesis (...) in the above table might change with each execution.