nimdokk has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with strict "refs"
by Limbic~Region (Chancellor) on Sep 22, 2003 at 19:54 UTC | |
|
Re: Problem with strict "refs"
by dragonchild (Archbishop) on Sep 22, 2003 at 19:59 UTC | |
|
Re: Problem with strict "refs"
by jeffa (Bishop) on Sep 22, 2003 at 19:54 UTC | |
|
Re: Problem with strict "refs"
by fletcher_the_dog (Friar) on Sep 22, 2003 at 20:04 UTC | |
|
Re: Problem with strict "refs"
by nimdokk (Vicar) on Sep 23, 2003 at 11:59 UTC |