title: Perl Error "Can't call method "get_tag" on an undefined value at Parser.pl line 6"
body: <p>I wrote a simple perl script but i am getting this runtime error:</p>
  
  <p>Can't call method "get_tag" on an undefined value at Parser.pl line 6</p>
  
  <p>Below is my code:</p>
  
  <pre><code>#!usr/bin/perl
  use HTML::TokeParser
  my $p=HTML::TokeParser-&gt;new('bad.html');
  while (my $token=$p-&gt;get_tag('a')){
  my $url=$token-&gt;[1]{href};
  print "$url\n";
  }
  </code></pre>
  
  <p>I have placed a file bad.html under the same directory of this perl program.
  Below is the code for bad.html</p>
  
  <pre><code>&lt;html&gt;&lt;body&gt;
  &lt;a href="https://www.Google.com"&gt;Google&lt;/a&gt;
  &lt;a href="https://www.yahoo.com"&gt;Yahoo&lt;/a&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Please help me on the error in running my perl code.</p>