Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
We don't bite newbies here... much
 
PerlMonks  

Re: How to print list as matrix

by Albannach (Prior)
on Aug 04, 2006 at 14:38 UTC ( #565673=note: print w/ replies, xml ) Need Help??


in reply to How to print list as matrix

I noticed in your data there is no object2,object1 value in contradiction with your output sample, but with that in mind I'd elect to assume that not all cells in the table will necessarily be defined, and so you may need to inspect all the data to discover all the possible column names.

use strict; use warnings; my %table; my %rows; my %cols; for(<DATA>) { my($row,$col,$val) = split ' '; $table{$row}{$col} = $val; $rows{$row}++; $cols{$col}++; } for my $col (sort keys %cols) { print "\t$col"; } print "\n"; for my $row (sort keys %rows) { print "$row\t"; for my $col (sort keys %cols) { print $table{$row}{$col} if defined $table{$row}{$col}; print "\t"; } print "\n"; } __DATA__ object1 object1 78 object1 object2 45 object1 object3 34 object1 object4 45 object2 object2 89 object2 object3 32 object2 object4 13

--
I'd like to be able to assign to an luser


Comment on Re: How to print list as matrix
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-04-20 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (487 votes), past polls