in reply to Split and join

G'day hellohello1,

Your main problem is that you print once only in the innermost loop. You need to print the parts before the ratios (without a newline) before that loop. Then print the ratios (still without a newline) inside that loop. Then print just a newline after that loop.

The output you say you're getting is not generated by the code you've posted! I'm not going to spend any time trying to guess which is right and what you really want.

Here's a rough approximation of the required code structure. I'll leave you to work out which fields you actually want to print and whether or not you're going to use the formatting you generate for the ratios.

#!/usr/bin/env perl use strict; use warnings; my @data; while (<DATA>) { next if $. == 1; push @data, [split]; } for my $i (@data) { for my $j (@data) { print "Ratio ($j->[0]:$i->[0]): "; printf ' %.4f', $j->[$_] / $i->[$_] for 3 .. $#$j; print "\n"; } } __DATA__ ID Record Time A B C D E F G A776 762.81 0.76 2 2 2 2 2 2 2 A872 762.91 1.23 4 4 4 4 4 4 4

Output:

Ratio (A776:A776): 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 Ratio (A872:A776): 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 2.0000 Ratio (A776:A872): 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 Ratio (A872:A872): 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000

-- Ken

Replies are listed 'Best First'.
Re^2: Split and join
by hellohello1 (Sexton) on Mar 07, 2014 at 05:31 UTC
    Thanks Kcott! I thought the output that I am getting got something to do with how I code the $ratio1 and I might be missing something since I split the data and have no idea how to make into the output I want. I will look through your code structure and try to make sense of it and work my way around. I'll reply here again if I encounter problems.

    I am learning Perl as I go along and this forum has been very helpful in my learning process :) Thanks guys...it has been very stimulating to read the suggestions and advices from you!

      I manage to get it working. Thanks a lot guys!