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
Global Symbol "$ipAddr" requires explicit package name
Here's the code
my $resolver = Net::DNS::Resolver->new;
my $dnsQuery = $resolver->search($hostIP[0]->getFirstChild->getData);
if ($dnsQuery) {
foreach my $rr ($dnsQuery->answer) {
next unless $rr->type eq "A";
my $ipAddr = ip2dec($rr->address);
}
}
print( "::".$ipAddr );
How would it be possible to declare a variable in this manner that would be accessible from outside of the loop?