Need Help with Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keanesf
    New Member
    • Jun 2008
    • 1

    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?
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    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 $#:

    Code:
    use strict;
    use warnings;
    my $nscans = [1,2];#<-- $nscans is a reference to an array
    if( $#{$nscans} > -1 ){
       print "true";
    }
    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:

    Code:
    print ref $nscans,"\n";
    If $nscans is an array it should print ARRAY.

    Comment

    Working...