I'm very close to the solution!
(But it takes a lot of time...)
It is about the last three lines.
With line one and two I'll get the right values.
Adding or averaging (/2) results in "0.0".
sprintf tricks doesn't seem to work.
Summary:
How can I add or average two indexed values?
(I'm new to hashes/arrays etc.)
my @col1; # '1st-line-of-pair' buffer
foreach (@unpaired) { # comment
open(DATA, $_) or die "Couldn't open $_ for reading: $!\n"; # Open file
chomp($_ = <DATA>); # input regel 1 and remove newline, skip headers
while (<DATA>) { # read line
chomp;
my @col2 = split /\t/; # split line on tabs
if (@col1) { # two lines read, i.e. pair available?
if ( $col1[$h{'A'}[0]] eq $col2[$h{'A'}[0]] # match on ID_1
&& $col1[$h{'O'}[0]] eq $col2[$h{'O'}[0]] # match on plan ID
&& $col1[$h{'Q'}[0]] eq $col2[$h{'Q'}[0]] # match on session date
&& $col1[$h{'R'}[0]] eq $col2[$h{'R'}[0]] # match on session time
) {
$col1[$h{'B'}[0]] .= "-".$col2[$h{'B'}[0]]; # Concatenate B for both lines: <val1>-<val2>
$col1[$h{'D'}[0]] = "Paired_Perl"; # This set is modified by Perl
$col1[$h{'Y'}[0]] = ($col1[$h{'Y'}[0]]); # correct value
$col2[$h{'Y'}[0]] = ($col2[$h{'Y'}[0]]); # correct value
$col1[$h{'Y'}[0]] = ($col1[$h{'Y'}[0]] + $col2[$h{'Y'}[0]]); # adding goes wrong "0.0" ....
Thanks again!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.