title: confusing filehandle in perl
body: <p>Have been playing with the following script but still couldn't understand the meaning behind the two different "kinds" of filehandle forms. Any insight will be hugely appreciated.</p>
  
  <pre><code>#! usr/bin/perl
  use warnings;
  use strict;
  open (FH, "example.txt") or die $!;
  
  while (&lt;FH&gt;) {
      my @line = split (/\t/, $_); {
          print "@line","\n";
      }
  }
  </code></pre>
  
  <p>The output is as expected: <code>@line</code> array contains elements from line 1,2,3 ... from <code>example.txt</code>. As I was told that <code>open (FH, example.txt)</code> is not as good as <code>open (my $fh, '&lt;', 'example.txt')</code>, I changed it but then confusion arose.</p>
  
  <p>From what I found, <code>$fh</code> is <code>scalar</code> and contains ALL info in <code>example.txt</code>. When I assigned an array to <code>$fh</code>, the array stored each line in <code>example.txt</code> as a component in the array. However, when I tried to further split the component into "more components", I got the error/warning message "<code>use of uninitialized value</code>". Below is the actual script that shows the error/warning message. </p>
  
  <pre><code>open (my $fh, '&lt;', 'example.txt') or die $!;
  foreach ($fh) {
      my @line = &lt;$fh&gt;;
      my $count = 0;
      for $count (0..$#line) {
          my @line2 = split /\t/, $line[$count];
          print "@line2";
          print "$line2[0]";
          }
      }
  </code></pre>
  
  <p><code>print "@line2"</code> shows the expected output but <code>print "$line2[0]"</code> invokes the error/warning message. I thought if <code>@line2</code> is a true array, <code>$line2[0]</code> should be okay. But why "uninitialized value" ??</p>
  
  <p>Any help will be appreciated. Thank you very much.</p>
  
  <p>Added -
  the following is the "actual" script (I re-ran it and the warning was there)</p>
  
  <pre><code>#! usr/bin/perl
  use warnings;
  use strict;
  open (my $fh, '&lt;', 'example.txt') or die $!;
  
  foreach ($fh) {
      my @line = &lt;$fh&gt;;
      print "$line[1]";
      my $count = 0;
      for my $count (0..$#line) {
      my @line2 = split /\t/, $line[$count];
      print "@line2";
      #my $line2_count = $#line2;
      #print $line2_count;
      print "$line2[3]";
      }
      }
  </code></pre>
  
  <p>The warning is still <code>use of uninitialized value $line2[3] in string at filename.pl line 15, &lt;$fh&gt; line3</code>.</p>