On Thu, Jun 28, 2012 at 4:44 PM, John W. Krahn <jwkr...@shaw.ca> wrote: > lina wrote: >> >> Hi, > > > Hello, > > >> I have some data like: >> >> 0.35 3.41 1 >> 0.35 4.24 1 >> 0.35 4.35 2 >> 0.36 0.36 1 >> 0.36 1.32 1 >> 0.36 1.45 1 >> 0.36 1.46 1 >> >> >> wish the output look like >> >> 0.36 1.32 1.45 1.46 3.41 4.24 4.35 >> 0.35 0 0 0 0 1 1 2 >> 0.36 1 1 1 1 0 0 0 > > > > $ echo "0.35 3.41 1 > > 0.35 4.24 1 > 0.35 4.35 2 > 0.36 0.36 1 > 0.36 1.32 1 > 0.36 1.45 1 > 0.36 1.46 1" | perl -e' > > my ( @columns, %data ); > while ( <> ) { > my ( $row, $col, $val ) = split; > $data{ $row }{ $col } = $val; > push @columns, $col; > } > > @columns = sort { $a <=> $b } @columns;
suppose there are duplications in the @columns, the data much more like: 0.35 1.32 3 0.35 4.35 2 0.36 0.36 1 0.36 1.32 1 0.36 1.45 1 0.36 1.46 1 How can I remove the duplications, uniq them? Thanks with best regards, > > print " @columns\n"; > for my $row ( sort { $a <=> $b } keys %data ) { > print join( " ", $row, map $_ ? " $_" : " 0", @{ $data{ $row } }{ > @columns } ), "\n"; > > } > ' > 0.36 1.32 1.45 1.46 3.41 4.24 4.35 > 0.35 0 0 0 0 1 1 2 > 0.36 1 1 1 1 0 0 0 > > > > John > -- > Any intelligent fool can make things bigger and > more complex... It takes a touch of genius - > and a lot of courage to move in the opposite > direction. -- Albert Einstein > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/