in reply to Re^6: array in different columns
in thread array in different columns
Try
poj#!perl use strict; my @array = qw( -- 0.0175 0.0483 0.0507 -- 0.0471 0.0483 -- 0.0287 --); my @column; my $curr_column = 0; my $rows = 0; while (@array) { if( $array[0] ne '--' ) { push @{ $column[ $curr_column ] }, shift @array; if( $rows < $#{ $column[ $curr_column ] } ) { $rows = $#{ $column[ $curr_column ] }; }; } else { $curr_column++; $column[ $curr_column] ||= [0]; # a new column shift @array; }; }; for my $row (0..$rows) { my @tmp = (); for (@column){ if ( exists ($_->[ $row - $rows -1 ]) ){ push @tmp,$_->[ $row - $rows - 1 ]; } } print join "\t", @tmp; print "\n"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: array in different columns
by Muflone82 (Novice) on Nov 23, 2016 at 13:52 UTC | |
by Marshall (Canon) on Nov 24, 2016 at 09:04 UTC |