I've gotten my Array of Hashes built the way I want it. However, I'm running into a small problem when I turn strict on. I get the message:
Can't use string ("XXX") as a HASH ref while 
"strict refs" in use at test.pl line 20, <LOG> line 1.

Here is the code I am looking at.

use strict; use warnings; my (@unix_data,@nt_data); open LOG, "nt_data.txt" or die "Cannot open unix_data.txt $!"; while (<LOG>) { chomp; my $hashname; my @keysandvalues; my @field = split /,/, $_; foreach (@field) { my ($key, $value) = split /\s*=\s*/, $_; if ($key =~ /^(LocalTran)(\w*)(Number)$/) { $hashname=$value; } push @keysandvalues, $key; push @keysandvalues, $value; } %{$hashname}=@keysandvalues; push @nt_data,\%{$hashname}; } foreach (@nt_data) { my $key; print "-+" x 90 . "\n"; foreach $key (keys %{$_}) {print "$key => ${$_}{$key}\n";} }

Of course it works properly when I set 'no strict "refs";' in the block, but I don't want to do that, I want to find out why I am running into this problem. I am currently reading through the Camel Book to find a solution, but thought I'd post it here as well to see if I can't learn something. Thanks in advance. I'm sure the answer is quite simple but I can't quite get my head around it right now.


"Ex libris un peut de tout"

In reply to Problem with strict "refs" by nimdokk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.