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
173 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now