[Milan-pm] incolonnare dati

Giulio Bertani gbjgiulio at gmail.com
Sun Nov 8 07:33:58 PST 2009


dato che ti arriva da un cut ... unix :
1) lo leggi da un file ( qui rappresentato da ___DATA___ )
2) lo leggi da STDIN se metti il programma in coda a tutto dopo un |.
3) Usi il programma perl con una open su comando filesystem.
per il punto 3 vedi il tutorial sul comando open

Ciao
Giulio
2009/11/5 Oha <oha at oha.it>

> un po spaghetti ma magari puo' esser uno spunto:
>
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> my %data;
> my %cols;
> while(<DATA>)
> {
>    chomp;
>    my @cols = split /s+/;
>    my $first = shift @cols or next;
>    my $second = shift @cols;
>    my %other = map { /([^(]+)((d+))*?/; $cols{$2}++; ($2,$1); } @cols;
>    $other{__perc} = $second;
>    $data{$first} = %other;
> }
>
> foreach my $k (sort keys %data)
> {
>    my $other = $data{$k};
>    print $k, "t", $other->{__perc}, "t";
>    foreach my $c (sort { $a <=> $b } keys %cols) {
>        my $v = $other->{$c};
>        print $v ? "$v($c)t" : "-t";
>    }
>    print "n";
> }
>
> __DATA__
> 1opj-A 100.0 M309(67)* F401(159)* F336(94)* I379(137)* A399(157)* K290(48)*
> I332(90)* Y272(30)* V275(33)* A288(46)* L267(25)* V318(76)* H380(138)*
> L389(147)* T334(92) D400(158) M337(95) E305(63)
> 2hyy-A 99.2 F382(147)* M290(55)* F317(82)* I360(125)* Y253(19)* A269(35)*
> H361(126)* L248(14)* A380(145)* K271(37)* V289(54)* I313(78)* L370(135)*
> V256(22)* I293(58)* V299(64)* D381(146) T315(80) M318(83) E286(51)
> 2pl0-A 48.3 Y318(88)* F383(153)* A271(41)* M319(89)* I361(131)* M292(62)*
> I314(84)* A381(151)* K273(43)* V301(71)* H362(132)* V259(29)* L291(61)*
> D382(152) T316(86) E288(58)
>
>
>
>
> _______________________________________________
> Milan-pm mailing list
> Milan-pm at pm.org
> http://mail.pm.org/mailman/listinfo/milan-pm
>



-- 
Giulio Bertani
www.perquelliche.it (In definizione ...)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/milan-pm/attachments/20091108/9a3fff04/attachment.html>


More information about the Milan-pm mailing list