awake416
awake416

Reputation: 301

perl hash confusion

Do you see anything wrong in the below expression.

    my $container;
    while (my $val = $details->next()){
          $container->{'total_vals'} += 1;
          my $section_name= 'some string from some db query';
          $container->{"$section_name"}->{'total_vals'} += 1;
    }
    print Dumper $section;

above code works when strict is not in use no strict. but the second key does not contain a valid value. while if strict sub is in use, i get the below warning. just let me know what I am missing.

Can't use string ("140360537348481") as a HASH ref while "strict refs" in use at source.pm line 61."

Upvotes: 0

Views: 148

Answers (1)

krico
krico

Reputation: 5728

This means that you probably set $container->{"$section_name"} = "140360537348481"; at some point. When you should have done $container->{"$section_name"} = {};.

Upvotes: 4

Related Questions