467,104 Members | 1,054 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

Need Help with Error

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
  • viewed: 1002
1 Reply
Expert 2GB
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";
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.

Similar topics

2 posts views Thread by lawrence | last post: by
6 posts views Thread by mike | last post: by
reply views Thread by ward@ | last post: by
5 posts views Thread by Chuck Anderson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.