S
superfly2
I have constructed an array of hashes (pointers to hash elements) and I have
the following problem when I foreach or for loop through the array and print
the hashes: Arrays of size < 18 print fine. But arrays >= 18 freeze after
the 18th elem (no matter what order i put the hashes into the array). I
don't know why 18 is the magic number, but it always is. In fact, I can
explicitly print elements 19, 20, and 21 before I print the first 18, but
then when I try to print the others, I can only print the first 15 (because
I printed 3 elements before...again 15+3 = 18! I don't get it).
I can print all the elements in the array (not just the first 18) if I print
only some of the hash values. I do not get any warnings when I run this
script.
Here is the relevant code, any help would be very much appreciated.
#!/usr/bin/perl -w
use strict;
use warnings;
my ($list) = @_;
my @arr = split("[\n\r]+", $list);
my @pairsAoH;
my $elem;
foreach $elem (@arr)
{
my %hash;
if ($elem =~ /[\t\|]/)
{
($hash{'name'}, $hash{'locus'}) = split("[\t\|]+", $elem);
$hash{'locus'} =~ s/^\s+//gm;
$hash{'locus'} =~ s/\s+$//gm;
}
else
{
$hash{'name'} = $elem;
}
$hash{'name'} =~ s/^\s+//gm;
$hash{'name'} =~ s/\s+$//gm;
push @pairsAoH, {%hash};
}
..
..
..
# code to fill in more of the hash value pairs
..
..
..
foreach my $item (@pairsAoH) #this prints fine
{
print "$$item{'name'}, $$item{'locus'}\n";
}
foreach my $hash (@pairsAoH) #only prints the first 18 and
freezes
{
print
"$$hash{'name'}\t\'$$hash{'locus'}\'\t\t$$hash{'start'}\t$$hash{'end'}\t\t$$
hash{'fbid'}\t$$hash{'cg'}\n";
}
the following problem when I foreach or for loop through the array and print
the hashes: Arrays of size < 18 print fine. But arrays >= 18 freeze after
the 18th elem (no matter what order i put the hashes into the array). I
don't know why 18 is the magic number, but it always is. In fact, I can
explicitly print elements 19, 20, and 21 before I print the first 18, but
then when I try to print the others, I can only print the first 15 (because
I printed 3 elements before...again 15+3 = 18! I don't get it).
I can print all the elements in the array (not just the first 18) if I print
only some of the hash values. I do not get any warnings when I run this
script.
Here is the relevant code, any help would be very much appreciated.
#!/usr/bin/perl -w
use strict;
use warnings;
my ($list) = @_;
my @arr = split("[\n\r]+", $list);
my @pairsAoH;
my $elem;
foreach $elem (@arr)
{
my %hash;
if ($elem =~ /[\t\|]/)
{
($hash{'name'}, $hash{'locus'}) = split("[\t\|]+", $elem);
$hash{'locus'} =~ s/^\s+//gm;
$hash{'locus'} =~ s/\s+$//gm;
}
else
{
$hash{'name'} = $elem;
}
$hash{'name'} =~ s/^\s+//gm;
$hash{'name'} =~ s/\s+$//gm;
push @pairsAoH, {%hash};
}
..
..
..
# code to fill in more of the hash value pairs
..
..
..
foreach my $item (@pairsAoH) #this prints fine
{
print "$$item{'name'}, $$item{'locus'}\n";
}
foreach my $hash (@pairsAoH) #only prints the first 18 and
freezes
{
"$$hash{'name'}\t\'$$hash{'locus'}\'\t\t$$hash{'start'}\t$$hash{'end'}\t\t$$
hash{'fbid'}\t$$hash{'cg'}\n";
}