Gossamer Forum
Quote Reply
Error: not a coderef
I have the following global:
Code:
sub {
my $ip_address = shift;
use strict;
use Net::DNS;
use IO::Select;

my $timeout = 5;
my $nameserver = "ns.phys.uu.nl";
my %host;
my $result;
my $res = new Net::DNS::Resolver;
$res->nameservers( $nameserver );
my $bgsock = $res->bgsend( $ip_address );
my $sel = new IO::Select($bgsock);
my @ready = $sel->can_read($timeout);
if (@ready) {
foreach my $sock (@ready) {
if ($sock == $bgsock) {
my $packet = $res->bgread($bgsock);
if ($packet) {
foreach my $rr ($packet->answer) {
my $hostname = $rr->rdatastr;
$hostname =~ s/\.$//g;
$result = $hostname;
}
}
else {
$result = $ip_address;
}
$bgsock = undef;
}
$sel->remove($sock);
$sock = undef;

}
}
else {
$result = $ip_address;
}
if ( $result eq "" ) { $result = $ip_address; }
return $result;
}

When I use <%hostlookup($online_ip)%>, I get Error: Variable 'hostlookup' is not a code reference

Any ideas what might cause this? The thing is, the code used to work in GForum v 1.0.0, but it doesn't in 1.1.1. I already tried to change the last line into "return \$result;" but that wouldn't work.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Error: not a coderef In reply to
Check for extra spaces or blank lines before the "sub" or between "sub" and "{" - the first 5 characters must be exactly: "sub {" (5 characters).

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [jagerman] Error: not a coderef In reply to
Jagerman, thanks for your answer.

I checked for extra spaces, newslines, everything, but it still did't work.

And I found some very strange behaviour: I copied the global hostlookup into a new global testsub (which strangely enough was working), then I deleted hostlookup and copied testsub into hostlookup. Now, hostlookup works as it used to.

Very strange...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Error: not a coderef In reply to
Oh... That's quite odd - it may be that the browser was hiding the first \n but sending it through when you saved. I'll try it out and see if I can figure out what was going on.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com