If'm testing to see if initially the hash's array value is empty. If it's not, I want to push a string value to the array.
I'm getting an error when I printing out the hash array values:
"can't use string ("2") as an ARRAY ref while "strict refs" in use".
This simple code works if I don't try to add to the array, so the problem is the bold statements.
What am I doing wrong? Thanks for any comments!!!
use warnings;
use strict;
my %ha_aid;
open (FILE,"fpf.temp") || ((warn "Can't open file: $!\n"), die);
while (<FILE>)
{
my @line = split;
if ($line[3] =~ /$ARGV[0]/)
{
if (@ha_aid{$line[2]})
{
print "not empty\n";
$ha_aid{$line[2]} = push (@{$ha_aid{$line[2]}}, $line [3]);
}
else
{
print "empty\n";
$ha_aid{$line[2]} = [$line[3]]; #anon array used?
}
}
}
close (FILE);
foreach my $x (keys %ha_aid)
{
print "Unique aid: $x \tFP: @{ $ha_aid{$x} } \n"
}
I'm getting an error when I printing out the hash array values:
"can't use string ("2") as an ARRAY ref while "strict refs" in use".
This simple code works if I don't try to add to the array, so the problem is the bold statements.
What am I doing wrong? Thanks for any comments!!!
use warnings;
use strict;
my %ha_aid;
open (FILE,"fpf.temp") || ((warn "Can't open file: $!\n"), die);
while (<FILE>)
{
my @line = split;
if ($line[3] =~ /$ARGV[0]/)
{
if (@ha_aid{$line[2]})
{
print "not empty\n";
$ha_aid{$line[2]} = push (@{$ha_aid{$line[2]}}, $line [3]);
}
else
{
print "empty\n";
$ha_aid{$line[2]} = [$line[3]]; #anon array used?
}
}
}
close (FILE);
foreach my $x (keys %ha_aid)
{
print "Unique aid: $x \tFP: @{ $ha_aid{$x} } \n"
}