Ask a Question related to PERL Miscellaneous, Design and Development.
-
superfly2 #1
wierd Array of Hash result
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{'st art'}\t$$hash{'end'}\t\t$$
hash{'fbid'}\t$$hash{'cg'}\n";
}
superfly2 Guest
-
Wierd query result on MySQL 5 system
I have the following table (complete with sample data). When I run the query below on a mysql 4.1.14 system, the only row returned is row 4 as... -
Updating an array within a hash
Hi Everybdy, I am stuck in a problem for which I need your help. My problem spins around adding an element in an array within a hash. I have a... -
hash of hash of array slices
This works Foreach ( @{$hash{$key1}{$key2}} ) This does note Foreach ( @{($hash{$key1}{$key2})} ) This gives me this error .... Can't... -
adding an array as a hash value
Hi Dermot. Dermot Paikkos wrote: And use warnings; These variables need to have better names so that it's more -
Wierd result from hash array
I'm getting 'used' to hash arrays and am writing a perl script to backup my harddrive automatically. I couldn't figure out how to get the... -
superfly2 #2
Re: wierd Array of Hash result
nevermind. i got it (printing unintialized values for some elems).
superfly2 Guest



Reply With Quote

