By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,812 Members | 1,978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,812 IT Pros & Developers. It's quick & easy.

Need Help with Error

P: 1
I program that I am trying to run keeps giving me the error

Can't use string ("2") as an ARRAY ref while "strict refs" in use at /usr/share/nmap-cgi/api//Nmap/CGI/Main.pm line 188.

I know I need to change the code around a bit to get it to work but I'm sure exactly what to do.

Here is Main.pm line 188

if( $#{@$nscans} > -1 )

What do I have to change?
Jun 28 '08 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
I think its better written without the @ symbol when dereferencing the array reference and getting the number of the last index of the array using $#:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. my $nscans = [1,2];#<-- $nscans is a reference to an array
  4. if( $#{$nscans} > -1 ){
  5.    print "true";
  6. }
The above code prints "true" when run with strict turned on. So I think the problem is elsewhere in your code. Are you sure $nscans is a reference to an array? Add this to your code and see what it prints:

Expand|Select|Wrap|Line Numbers
  1. print ref $nscans,"\n";
  2.  
If $nscans is an array it should print ARRAY.
Jun 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.