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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
transpose into pipe delemited 8 85
Problem with one substitution modifying another 3 83
Perl string filter 5 88
Perl tar error 8 72
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

738 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