Solved

Newbie-- HELP! : (F) Perl was trying to evaluate a reference to a code value (that is, a subroutine), but found a reference to something else instead.

Posted on 2006-11-05
4
197 Views
Last Modified: 2010-03-05
Can someone PLEASE tell me what is wrong with this code.  I've been trying to figure it out for 2 hours.
i just started learning perl.  I've never seen any error like this. Not even in C.

#!/usr/bin/perl -w

###########################
###### Description     ############
### A basic site pinger ############
### ########################
###########################

use strict;
use warnings;
use diagnostics;

use Net::Ping;

if (@ARGV)
   {
      my $host = shift;
      chomp($host);
      my $err = pingIt($host);
   }
else
   {
    print "usage: pingtest <hostname>";
   }


 sub pingIt
 {
     my $p = Net::Ping->new("icmp");
     my $retStat = $p->($_[0], 4);
     $p->close();
     return($retStat);
 }
0
Comment
Question by:TristinColby
  • 2
4 Comments
 
LVL 6

Expert Comment

by:tone28
ID: 17876145
#!/usr/bin/perl -w

###########################
###### Description     ############
### A basic site pinger ############
### ########################
###########################

use strict;
use warnings;
use diagnostics;

use Net::Ping;

if (@ARGV)
   {
      my $host = shift;
      chomp($host);
      my $err = pingIt($host);
        if($err) {
            print $err;
          }
        else {
            print "Not init";
        }
   }
else
   {
    print "usage: pingtest <hostname>";
   }


 sub pingIt
 {
     my $p = Net::Ping->new("icmp");
     my $retStat = $p->ping($_[0], 4);
     $p->close();
     return($retStat);
 }



in the pinigIt sub you forgot to add ping to the p->($_[0],4)  --> p->ping($_[0],4)


0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 17876153
sub pingIt
 {
     my $p = Net::Ping->new("icmp");
     my $retStat = $p->ping($_[0], 4);
     $p->close();
     return($retStat);
 }
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 17876160
Oops -- tone28 beat me to it.  Note that you might also want to scope $host and $err outside of the "if" loop if you'll want to use them elsewhere:

#!/usr/bin/perl -w

###########################
###### Description     ############
### A basic site pinger ############
### ########################
###########################

use strict;
use warnings;
use diagnostics;
use Net::Ping;

my ($host, $err);

if (@ARGV)
   {
      $host = shift;
      chomp($host);
      $err = pingIt($host);
   }
else
   {
    print "usage: pingtest <hostname>";
   }

 sub pingIt
 {
     my $p = Net::Ping->new("icmp");
     my $retStat = $p->ping($_[0], 4);
     $p->close();
     return($retStat);
 }
0
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 17877381
I'd write it as

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Net::Ping;

die "USAGE: $0 <hostname>\n" unless @ARGV;
my $err = pingIt(@ARGV);

sub pingIt {
     my $host = shift;

     my $p = Net::Ping->new("icmp");
     my $retStat = $p->ping($host, 4);
     $p->close();
     return $retStat ;
}
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question