title: Perl's odd behavior when reassigning a filehandle variable from STDOUT to a file without undef()
body: <p>When executing the following simplified code:</p>
  <pre><code>use strict;                                          # [01]
  use warnings FATAL =&gt; 'unopened';                    # [02]
                                                       # [03]
  my ($inHandle, $outHandle) = (\*STDIN, \*STDOUT);    # [04]
  print $outHandle &quot;STDOUT  1\n&quot;;                      # [05]
                                                       # [06]
  # $outHandle re-assigned to outputA.txt ???          # [07]
  open($outHandle, &quot;&gt;outputA.txt&quot;) or die (&quot;A: $!\n&quot;); # [08]
  print $outHandle &quot;FILE A\n&quot;;                         # [09]
  print             &quot;STDOUT? 2\n&quot;;                     # [10]
  print STDOUT      &quot;STDOUT  3\n&quot;;                     # [11]
  close $outHandle;                                    # [12]
                                                       # [13]
  # $outHandle is closed                               # [14]
  print STDOUT      &quot;STDOUT  4\n&quot;;                     # [15]
  print             &quot;STDOUT? 5\n&quot;;                     # [16]
  print $outHandle &quot;FILE CLOSED\n&quot;;                    # [17]
                                                       # [18]
  # $outHandle re-assigned to outputA.txt ???          # [19]
  open($outHandle, &quot;&gt;outputB.txt&quot;) or die (&quot;B: $!\n&quot;); # [20]
  print $outHandle &quot;FILE B\n&quot;;                         # [21]
  close $outHandle;                                    # [22]
  </code></pre>
  <p>I encounter these following odd behaviors:</p>
  <ol>
  <li>No warning is raised when printing (line [18]) to a closed (unopened) <code>$outputHandle</code> (line [13]), even when <code>use warnings FATAL =&gt; 'unopened';</code> is used.</li>
  <li>The output is as follows which is not what I expect.</li>
  </ol>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">STDOUT</th>
  <th style="text-align: left;">outputA.txt</th>
  <th style="text-align: left;">outputB.txt</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">STDOUT  1</td>
  <td style="text-align: left;">FILE A</td>
  <td style="text-align: left;">FILE B</td>
  </tr>
  <tr>
  <td style="text-align: left;"></td>
  <td style="text-align: left;">STDOUT? 2</td>
  <td style="text-align: left;"></td>
  </tr>
  <tr>
  <td style="text-align: left;"></td>
  <td style="text-align: left;">STDOUT  3</td>
  <td style="text-align: left;"></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>This is the output I expect assuming line [17] is commented out and doesn't raise the <code>warnings FATAL =&gt; 'unopened'</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">STDOUT</th>
  <th style="text-align: left;">outputA.txt</th>
  <th style="text-align: left;">outputB.txt</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">STDOUT  1</td>
  <td style="text-align: left;">FILE A</td>
  <td style="text-align: left;">FILE B</td>
  </tr>
  <tr>
  <td style="text-align: left;">STDOUT? 2</td>
  <td style="text-align: left;"></td>
  <td style="text-align: left;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">STDOUT  3</td>
  <td style="text-align: left;"></td>
  <td style="text-align: left;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">STDOUT  4</td>
  <td style="text-align: left;"></td>
  <td style="text-align: left;"></td>
  </tr>
  <tr>
  <td style="text-align: left;">STDOUT? 5</td>
  <td style="text-align: left;"></td>
  <td style="text-align: left;"></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>As a side note:</p>
  <ol>
  <li>The original program outputs to STDOUT as default but switches to outputting to a file if there is a parameter passed to the program.</li>
  <li>I am using &quot;This is perl 5, version 28, subversion 1 (v5.28.1) built for MSWin32-x64-multi-thread&quot;</li>
  </ol>