Hello monks! Hope you are doing well I am trying to read a file which has three columns and store the content in a hash. Now i want to store the first column data as keys and third column data as a values, here is the file

GeneName GeneType Regulation APOL4 protein_coding up CYP2C8 protein_coding down NAALADL2 protein_coding NA NANOS3 protein_coding up C20orf204 protein_coding up MIR429 miRNA up MIR200A miRNA down MIR200B miRNA down CFL1P4 processed_pseudogene down AC091607.1 processed_pseudogene up RPL19P20 processed_pseudogene up SREK1IP1P1 processed_pseudogene down CCT5P2 processed_pseudogene up CHTF8P1 processed_pseudogene NA FAR1P1 processed_pseudogene NA AC067940.1 processed_pseudogene up AL662791.1 lncRNA up

here is my code which sets the second column as a value but i want to set the third column as a value in hash

open FILE1, "data.txt" or die; my %hash; while (my $line=<FILE1>) { chomp $line; (my $word1,my $word2) = split( /\s+/, $line); $hash{$word1} = $word2; } @values = values(%hash); print @values;

How can i split the second column out of the file?


In reply to ead a file which has three columns and store the content in a hash by shabird

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.