Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: ead a file which has three columns and store the content in a hash

by BillKSmith (Monsignor)
on Apr 16, 2020 at 15:32 UTC ( [id://11115639]=note: print w/replies, xml ) Need Help??


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

The array-of-arrays returned by the module Text::CSV_XS is a more appropriate data structure. It works well with other modules to compute and print your sums.
use strict; use warnings; # node_id=11115481 use Text::CSV_XS qw( csv ); use List::MoreUtils qw(first_index true); my $aoa = csv(in=>'data.csv', sep_char=>"\t"); my $header = shift @$aoa; use constant REGULATION => first_index {/^Regulation$/} @$header; printf "Number of up is: %d\n" ."Number of down is: %d\n" ."Number of NA is: %d\n", map {count($_)} qw(up down NA); exit(0); sub count{ my $Regulation = $_[0]; local $_; return true {$_->[REGULATION] eq $Regulation } @$aoa; }

OUTPUT:

Number of up is: 9 Number of down is: 5 Number of NA is: 3
Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found