in reply to Re: Subarray in a hash: Can't use string ("STRING") as a HASH ref while "strict refs" in use
in thread Subarray in a hash: Can't use string ("STRING") as a HASH ref while "strict refs" in use

That did it! Is this just because it's a hash within an array? Normally, when defining a hash (as %hashname), you use round parentheses - at least that's what the Perl Cookbook says.
Thanks!
  • Comment on Re^2: Subarray in a hash: Can't use string ("STRING") as a HASH ref while "strict refs" in use

Replies are listed 'Best First'.
Re^3: Subarray in a hash: Can't use string ("STRING") as a HASH ref while "strict refs" in use
by choroba (Cardinal) on Apr 08, 2014 at 13:51 UTC
    ( ) are used for assignments to arrays and hashes. [ ] are used for array references, { } are used for hash references. You are not assigning a hash, you are assigning a hash reference here.

    Updated.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      No, ( ) is used for lists. Lists are converted into arrays by assignment. Also, lists are converted into hashes by assignment.

      Example: note the addition of the `undef` to make the hash work properly.

      #!/usr/bin/env perl use strict; use warnings; use feature qw( :all ); # -------------------------------------- # Modules use Data::Dumper; # Make Data::Dumper pretty $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 1; # Set maximum depth for Data::Dumper, zero means unlimited local $Data::Dumper::Maxdepth = 0; # -------------------------------------- my @a = my %h = ( 1, 2, 3 ); say Dumper \@a; say Dumper \%h;
Re^3: Subarray in a hash: Can't use string ("STRING") as a HASH ref while "strict refs" in use
by andal (Hermit) on Apr 08, 2014 at 13:52 UTC

    Compare

    %hash = (key1 => 'val1', key2 => 'val2'); $hash = {key1 => 'val1', key2 => 'val2'};
    The first one defines hash, the second defines reference to hash, which is scalar.