title: How can I access a variable outside a loop when I set in it inside the loop?
body: <p>I wrote a quick Perl script to query the local DNS servers for an IP address, and I have a variable that needs to be declared within the scope of the loop, but it doesn't seem to be in scope outside of the loop.  The compiler is returning the errors</p>
  
  <pre>
  Global Symbol "$ipAddr" requires explicit package name
  </pre>
  
  <p>Here's the code</p>
  
  <pre><code>my $resolver = Net::DNS::Resolver-&gt;new;
  
  my $dnsQuery = $resolver-&gt;search($hostIP[0]-&gt;getFirstChild-&gt;getData);
  
  if ($dnsQuery) {
      foreach my $rr ($dnsQuery-&gt;answer) {
          next unless $rr-&gt;type eq "A";
          my $ipAddr = ip2dec($rr-&gt;address);
      }
  }
  
  print( "::".$ipAddr );
  </code></pre>
  
  <p>How would it be possible to declare a variable in this manner that would be accessible from outside of the loop?</p>