wierd Array of Hash result

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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
    5. 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...
  3. #2

    Default Re: wierd Array of Hash result

    nevermind. i got it (printing unintialized values for some elems).


    superfly2 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139