Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: List manipulation

by kcott (Archbishop)
on May 31, 2012 at 21:26 UTC ( [id://973615]=note: print w/replies, xml ) Need Help??


in reply to List manipulation

I saw Not_a_Number's solution as I was about to post mine. I've added his extra test data plus an additional one of my own which has nothing in either column 2 or 3.

#!/usr/bin/env perl use 5.010; use strict; use warnings; my %result; while (<DATA>) { map { $result{$_->[0]}[0] += defined $_->[1] && $_->[1] eq q{1_x} ? +1 : 0; $result{$_->[0]}[1] += defined $_->[2] ? 1 : 0; } ([split]); } say qq{$_ }, join q{,} => @{$result{$_}} for sort keys %result; __DATA__ A 1_x 9_z A 1_x A 1_x g_z B 2_c B 1_x 1_z C 1_x 1_z C v_x 8_z D v_x s_x E 1_x F

This outputs:

$ pm_extract_1_x.pl A 3,2 B 1,1 C 1,2 D 0,1 E 1,0 F 0,0

-- Ken

Replies are listed 'Best First'.
Re^2: List manipulation
by Anonymous Monk on Jun 01, 2012 at 08:29 UTC
    OP here. That looks brilliant thanks very much for that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 01:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found