Hello,
I am parsing a file and extracting two columns to use as key value pairs in a
hash. After parsing the file and assigning the key value pairs my hash is empty when there should be 24750 key value pairs.
Any ideas on how I can get all of the key value pairs into the hash?

#!/usr/bin/perl -w use strict; use Data::Dumper; #open file open(IN,"CCDS.20090902.txt") or die " Can't open ccds file: $!"; # initialize the hash my %geneids =(); #open the file and push the info from the designated columns into it # remove header my $firstline = <IN>; chomp $firstline; while(<IN>){ chomp; # remove the newline character my @fields = split (/\t/, $_); #extract the columns that we are interested in. my($key, $value) = ($fields[2], $fields[3]); # Populate the key value pairs of the hash with $gene and $id $geneids{$key} = $value; print "$key\t$value\n"; } # We can also get the size of the hash print "Hash size: ", scalar keys %geneids, "\n"; close(); __DATA__ #chromosome nc_accession gene gene_id ccds_id ccds_stat +us 1 NC_000001.8 NCRNA00115 79854 CCDS1.1 Withdrawn 1 NC_000001.10 SAMD11 148398 CCDS2.2 Public 1 NC_000001.10 NOC2L 26155 CCDS3.1 Public 1 NC_000001.10 PLEKHN1 84069 CCDS4.1 Public 1 NC_000001.10 HES4 57801 CCDS5.1 Public 1 NC_000001.10 ISG15 9636 CCDS6.1 Public 1 NC_000001.10 C1orf159 54991 CCDS7.2 Public 1 NC_000001.10 TTLL10 254173 CCDS8.1 Public 1 NC_000001.10 TNFRSF18 8784 CCDS9.1 Public 1 NC_000001.10 TNFRSF18 8784 CCDS10.1 Public 1 NC_000001.10 TNFRSF4 7293 CCDS11.1 Public 1 NC_000001.10 SDF4 51150 CCDS12.1 Public 1 NC_000001.10 B3GALT6 126792 CCDS13.1 Public 1 NC_000001.10 UBE2J2 118424 CCDS14.1 Public


LomSpace

In reply to How do I dynamically populate a hash after parsing columns from a file by lomSpace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.