chrisantha, try this:

#!/perl/bin/perl -w use strict; use Data::Dumper; my $hash = {}; for (<DATA>) { chomp; my @fields = split(/\s{4}/, $_); my @genes = split(',', $fields[3]); @genes = map { (split('\|'))[1] } @genes; push(@{$hash->{$fields[0]}}, \@genes); } print Dumper($hash); __DATA__ malS 1 forward malS|b3571, malT 1 forward malT|b3418, malXY 2 forward malX|b1621,malY|b1622, malZ 1 forward malZ|b0403, manA 1 forward manA|b1613, __OUTPUT__ $VAR1 = { 'malZ' => [ [ 'b0403' ] ], 'malS' => [ [ 'b3571' ] ], 'manA' => [ [ 'b1613' ] ], 'malXY' => [ [ 'b1621', 'b1622' ] ], 'malT' => [ [ 'b3418' ] ] };

Is this what you're looking for?

Updated: Added __OUTPUT__


Where do you want *them* to go today?

In reply to Re: Getting data from a file (Operons and Genes). by thezip
in thread Getting data from a file (Operons and Genes). by chrisantha

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.