title: Perl 'My' Variable [$] makes earlier declaration in same statement
body: <p>So I have a few sub rutines for opening a file:</p>
  
  <pre><code>828 sub open_for_r {
  829     my $FH = shift;
  830     my $filename = shift;
  831 
  832     open($FH, "&lt; $filename") || die "cannot open $filename: $!";
  833 }
  834 
  835 sub open_for_w {
  836     my $FH = shift;
  837     my $filename = shift;
  838 
  839     open($FH, "&gt; $filename") || die "cannot open $filename: $!";
  840     # open($FH, "&gt;&gt; $filename") || die "cannot open $filename: $!";
  841 }
  842 
  843 sub open_for_rw {
  844     my $FH = shift;
  845     my $filename = shift;
  846 
  847     open($FH, "+&lt; $filename") || die "cannot open $filename: $!";
  848     # open($FH, "&gt;&gt; $filename") || die "cannot open $filename: $!";
  849 
  850 }
  851 
  852 sub read_file {
  853 
  854     my $FH = shift;
  855     my $filename = shift;
  856     my $contents = "";
  857     my $var = "";
  858 
  859     #To read from that file
  860     while (defined($var = &lt;$FH&gt;)) {
  861         # chomp($var);
  862         # print "$var\n";
  863     $contents .= $var;
  864     }
  865     return $contents;
  866 }
  </code></pre>
  
  <p>Now I am getting a warning:</p>
  
  <p><strong>"my" variable $FH masks earlier declaration in same scope at ittp_to_scn.pl line 836.</strong></p>
  
  <p><strong>"my" variable $filename masks earlier declaration in same scope at ittp_to_scn.pl line 837.</strong></p>
  
  <p><strong>"my" variable $FH masks earlier declaration in same scope at ittp_to_scn.pl line 844.</strong></p>
  
  <p><strong>"my" variable $filename masks earlier declaration in same scope at ittp_to_scn.pl line 845.</strong></p>
  
  <p>Although nowhere else in my code do I have the <strong>$FH</strong> or <strong>$filename</strong> declared. I don't understand why it is saying that there is an earlier declaration? Aren't I allowed to use the same variable names in different sub routines? Or is this not allowed in Perl?</p>