Ganesh Bharadwaj1 has asked for the wisdom of the Perl Monks concerning the following question:
I want my input2.txt file to look like923.066 923.813 432.895 433.381 M1 M2
This is the code I have written.923.066 432.895 M1 923.813 433.381 M2
#!/usr/bin/perl use strict; use File::Path qw(rmtree); my @rows = (); my @transposed = (); open F1,"input.txt"; while(<F1>) { chomp; push @rows, [ split / / ]; } #print @rows; my $filein2 = "input2.txt"; unlink $filein2; open my $fileHandlein2, ">>", "input2.txt" or die "Can't open 'input2. +txt'\n"; for my $row (@rows) { for my $column (0 .. $#{$row}) { push(@{$transposed[$column]}, $row->[$column]); } } for my $new_row (@transposed) { for my $new_col (@{$new_row}) { print $fileHandlein2 $new_col, " "; } print "\n"; }
The output file generated looks like
500.000 1333.000 M1 600.000 1130.000 M3Could you please let me know what mistake I am doing and how to modify my code so that I can get the transposed file?
thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Transpose a file
by VinsWorldcom (Prior) on May 09, 2016 at 12:21 UTC | |
|
Re: Transpose a file
by karlgoethebier (Abbot) on May 09, 2016 at 12:51 UTC | |
|
Re: Transpose a file
by Corion (Patriarch) on May 09, 2016 at 11:10 UTC | |
|
Re: Transpose a file
by Discipulus (Canon) on May 09, 2016 at 11:13 UTC | |
by Lotus1 (Vicar) on May 09, 2016 at 14:21 UTC | |
|
Re: Transpose a file
by NetWallah (Canon) on May 09, 2016 at 21:52 UTC | |
by Discipulus (Canon) on May 11, 2016 at 08:24 UTC | |
by choroba (Cardinal) on May 11, 2016 at 13:24 UTC | |
by Discipulus (Canon) on May 11, 2016 at 19:25 UTC | |
by NetWallah (Canon) on May 11, 2016 at 13:59 UTC |