techperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am getting below mentioned error, for which I couldn't find any solution.

>Can't use an undefined value as an ARRAY reference at line 668.

Code at line 668,
for ( my $i = 0; $i < scalar( @{$dataSet{results}} ); $i++ )

Kindly provide me a solution.....

Thanks.
  • Comment on Can't use an undefined value as an ARRAY reference

Replies are listed 'Best First'.
Re: Can't use an undefined value as an ARRAY reference
by Corion (Patriarch) on Jan 09, 2009 at 08:28 UTC

    Obviously, $dataSet{results} is not defined.

    See Data::Dumper for dumping the contents of %dataSet.

Re: Can't use an undefined value as an ARRAY reference
by andye (Curate) on Jan 09, 2009 at 10:03 UTC
    You might also find 'use diagnostics;' useful - put this at the top of your program and it'll give you more explainey error messages.
      Hello, if $dataSet{results} is parsed from a user input file for example, and we would want to give user the flexibility of defining and not defining this array depending on their applications, is there a way I could get around this without getting the error of "undefined value as an ARRAY reference" ? Thanks!
Re: Can't use an undefined value as an ARRAY reference
by perlthirst (Scribe) on Jan 09, 2009 at 09:21 UTC
    there is no value available in $dataSet{results}. print this and check whether Array Ref is available or not.