title: Perl Global symbol requires explicit package name
body: <p>I am trying to store my log messages in a hash depending upon message type as shown below:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  
  my %log;
  
  opendir (DIR, '.') or die $!;
  while (my $file = readdir(DIR)) {
      # some code to select TAR filename in $1
      if (-e $1.'.tar') {
          push(@{$log-&gt;{$1}}, $file); /* line 12 */
      }
      else {
          $log{$1} = [];
          push(@{$log-&gt;{$1}}, $file); /* line 16 */
  }
  </code></pre>
  
  <p>Now this code gives compilation error saying:</p>
  
  <pre><code>Global symbol "$log" requires explicit package name at at lines 12 &amp; 16
  </code></pre>
  
  <p>where I am actually trying to use the hash "%log". What can be a possible way to get rid of this error ? Why exactly is this happening ?</p>
  
  <p>I did see some explanation on context where people replied saying the variables were created in one context and were being referred in another but I feel this variable should be available inside while loop in this piece of code. This happens only when I have "use strict" and works fine otherwise.</p>
  
  <p>I have started with Perl so I do not fully understand the basics! Please help me understand why this variable is not accessible.</p>