wierd Array of Hash result

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";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top