Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: format conversion, please help

by Kenosis (Priest)
on Apr 06, 2013 at 20:39 UTC ( #1027302=note: print w/ replies, xml ) Need Help??


in reply to format conversion, please help

And here's one more (perhaps "ugly" :) option:

use strict; use warnings; my @col1 = split ' ', <DATA>; <DATA>; my @rows = map { my @row = split; \@row } <DATA>; my $i = 2; for my $col (@col1) { print "$col\t$_->[0]\t$_->[1]\t$_->[$i]\n" for @rows; $i++; } __DATA__ A C F SampleID Time ObsConc ObsConc ObsConc 5 24 2.27E+06 687.02 32521.94 5 168 1.92E+06 525.02 22198.44 5 12 2.94E+06 896.39 41331.61 5 -0.5 2.23E+06 942.34 40616.49 5 8 4.03E+06 1371.32 45863.69 6 24 1.02E+06 1057.89 46341.04 6 168 3.14E+06 4987.32 42166.08

Output:

A 5 24 2.27E+06 A 5 168 1.92E+06 A 5 12 2.94E+06 A 5 -0.5 2.23E+06 A 5 8 4.03E+06 A 6 24 1.02E+06 A 6 168 3.14E+06 C 5 24 687.02 C 5 168 525.02 C 5 12 896.39 C 5 -0.5 942.34 C 5 8 1371.32 C 6 24 1057.89 C 6 168 4987.32 F 5 24 32521.94 F 5 168 22198.44 F 5 12 41331.61 F 5 -0.5 40616.49 F 5 8 45863.69 F 6 24 46341.04 F 6 168 42166.08

Hope this helps!

Edit: My thanks to poj for pointing out that my script didn't properly generate the last column's values. This is fixed.


Comment on Re: format conversion, please help
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-29 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls