3
votes

I have

 my $test_case_list  = [
     +{     
         label => &config->current->{'DBI'}[0],
         expected => 'dbi:mysql:dbname=investometrica',
      },     
      +{     
          label => &config->current->{'maintenance_file_path'}[0],
          expected => '/var/tmp/',
      },     
  ];         


  for my $test_case_item (@$test_case_list) {
  my $label = @{ $test_case_item->{label} };
  my $expected = @{ $test_case_item->{expected} };
  is ( $label, $expected, "Match");                                                                                                                                                                                 
  } 

This gives me an awful warning:

Can't use string ("dbi:mysql:dbname=investometrica") as an ARRAY ref while "strict refs" in use at config.t line 25.

What am I doing wrong?

1
$test_case_item->{expected} is a string, why are you casting into a list? - perreal
Read the error message. It's telling you that you're trying to use a string as an array reference. Stop doing that. - user554546
@perreal: "casting into a list" is not a perl concept - ysth

1 Answers

4
votes

The items of @$test_case_list are hash references, whose keys are label and expected. The values for both keys are scalars (that are not array references). So you can't and/or shouldn't treat them as array references. But this is what you do if you use @{...} on them (such as in @{ $test_case_item->{label} }). Since they are already the scalars with the value you want, you should just go with $test_case_item->{label} instead.