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


In reply to Re: Split and join by kcott
in thread Split and join by hellohello1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.