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
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hard perl script 16 162
Which version of C should I use when Perl is too slow? 13 187
Check file date before getting folder path 1 84
Control Number of Log Files -Perl 7 94
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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

756 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