`cat file` is maybe slower, maybe not good style, but gives you list of lines from without having to bohter about open, close and so on. But if you need such precise control -- let somebody else do it -- that is Path::Tiny.

#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; no warnings qw{uninitialized}; use Data::Dumper; use Path::Tiny; my %myhash = map { ($$_[0], $$_[2]) } map { [split /\s+/, $_] } `cat myfile`; # maybe slower, but don't care +about open # path("myfile")->lines_utf8; # very reliable print Dumper(\%myhash); result: $VAR1 = { 'AC067940.1' => 'up', 'CCT5P2' => 'up', 'GeneName' => 'Regulation', 'C20orf204' => 'up', 'NANOS3' => 'up', 'MIR200A' => 'down', 'SREK1IP1P1' => 'down', 'AC091607.1' => 'up', 'CYP2C8' => 'down', 'AL662791.1' => 'up', 'FAR1P1' => 'NA', 'MIR200B' => 'down', 'CHTF8P1' => 'NA', 'RPL19P20' => 'up', 'MIR429' => 'up', 'APOL4' => 'up', 'CFL1P4' => 'down', 'NAALADL2' => 'NA' };

counting:

#!/usr/bin/perl -CSDA use utf8; use Modern::Perl; no warnings qw{uninitialized}; use Data::Dumper; use Path::Tiny; my %count; $count{$_}++ for map { $$_[2] } map { [split /\s+/, $_] } path("myfile")->lines_utf8; print Dumper(\%count); $VAR1 = { 'down' => 5, 'NA' => 3, 'up' => 9, 'Regulation' => 1 };

In reply to Re: ead a file which has three columns and store the content in a hash by leszekdubiel
in thread 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.