Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello dear Monks,
I have this file:
Is this correct code?
I have this file:
and I want to end up with 4 arrays, which will be the following ones (but created on-the-fly).METHOD 0TM 1TM 2TM >2TM method1 3 68 18 10 method2 3 80 10 6 method3 3 87 9 1 method4 5 83 9 3 method5 6 75 15 4 method6 14 77 6 3 method7 12 82 2 3 method8 9 84 3 3 method9 13 68 16 3 method10 5 65 20 9 method11 9 64 20 7 method12 5 68 18 9 method13 6 82 9 2 method14 11 79 8 2 method15 6 69 20 5 method16 5 80 11 3 method17 1 68 17 14
@x = qw(method1 method2 method3 method4 method5 method6 method7 method +8 method9 method10 method11 method12 method13 method14 method15 metho +d16 method17); @y1 = (3, 3, 3, 5, 6, 14, 12, 9, 13, 5, 9, 5, 6, 11, 6, 5, 1); @y2 = (68, 80, 87, 83, 75, 77, 82, 84, 68, 65, 64, 68, 82, 79, 69, 80, + 68); @y3 = (18, 10, 9, 9, 15, 6, 2, 3, 16, 20, 20, 18, 9, 8, 20, 11, 17); @y4 = (10, 6, 1, 3, 4, 3, 3, 3, 3, 9, 7, 9, 2, 2, 5, 3, 14);
Is this correct code?
open IN, "$infile" or die $!; @lines = <IN>; close IN; #get first line which will be the header line and keep only the titles + we need (the column names) $header_line = shift (@lines); @split_header = split(/\t/, $header_line); shift (@split_header); #work with the rest of the input file for ($i=0; $i<=$#lines; $i++) { $method_line = $_; #lines with the methods and the results for +each one @split_method = split(/\t/, $method_line); $method_name= shift (@split_method); #get only the name of the me +thod push @methods, $method_name; push @AoA, [ @split_method ]; #keep the data } unshift @AoA, [ @methods ];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is this the correct structure?
by moritz (Cardinal) on Jul 04, 2013 at 18:15 UTC | |
Re: Is this the correct structure?
by 2teez (Vicar) on Jul 04, 2013 at 20:28 UTC | |
by Anonymous Monk on Jul 04, 2013 at 23:11 UTC | |
by poj (Abbot) on Jul 05, 2013 at 11:06 UTC | |
by Anonymous Monk on Jul 05, 2013 at 12:47 UTC | |
by poj (Abbot) on Jul 05, 2013 at 13:04 UTC | |
| |
Re: Is this the correct structure?
by hermes1908 (Novice) on Jul 04, 2013 at 18:44 UTC | |
Re: Is this the correct structure?
by poj (Abbot) on Jul 04, 2013 at 18:45 UTC | |
Re: Is this the correct structure?
by code-ninja (Scribe) on Jul 05, 2013 at 12:22 UTC |
Back to
Seekers of Perl Wisdom