Hi, please help. I'm very new to Perl and coding, I have a big file with 15 columns and some with missing information. What I'm trying to do, is select column [ 13] with missing information and column [ 14] with no missing information; and then use column [ 4] as a key to map to column [ 2] and print all lines in column [ 2].

Here's how my data file looks like (tab delimited):

BC000 1 1 2 3 F 3 51 51 + BC000 0 2 M 999 BC000 0 3 37 36 F 65 + BC000 0 4 2 3 M 50 +50 BC000 0 5 2 3 F 45 47 + 46 BC000 0 6 2 3 F 3 42 + BC000 0 7 2 3 M 99 +9 BC000 0 8 2 3 F 3 42 + BC000 0 9 2 3 F 1 39 + BC000 0 10 2 3 F 3 35 + BC000 0 11 45 8 M 11 + BC000 0 12 45 8 F 9

Basically: column [ 13] = year of birth column [ 4] = motherID column [ 2] = individualID All motherIDs will have an individualID (the same as motherID) Here's my code:

#!/usr/bin/perl use warnings; use strict; my $filename = 'pedigree_proband_testfile.txt'; open (FILE, "<", $filename) or die "Cannot open file $!"; my @data = <FILE>; my @column; my $motherID; foreach my $line (@data) { @column = split ( /\t/, $line); if ($column[13] eq "" && $column[4] ne "" ) { $motherID = join($column[2],$column[4]); if ("$motherID" eq "$column[2]") { print "$line\t\n"; } } }

I tried this but it doesn't return any values. Can you please help? I'm really new to this, I'm trying to write a script to avoid mapping the columns manually in MS Excel as it's a big file with over 4000 rows. Many many thanks in advance!


In reply to How to map data from one column based on another column in perl by waekit

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.