The description of the problem is not enough for me to figure out what you want as an end objective.

So, as a clarification step, I wrote code to print the columns of interest (the ones that you mentioned).
In the code below, I translated the column indices into names based upon your post. Usually it is a good idea to use a meaningful name for a column instead of a number just because that is much easier for humans to understand. Perl is very flexible in how this can be done.

Please explain what the desired output is for each line below.

Also, in my opinion a tab delimited file is a difficult critter to deal with because it is difficult to see the difference between space and tab. I guess you are exporting this from an Excel table? Better is to use standard CSV or I often use pipe "|" delimiters for files that may be subsequently modified by humans. Humans cannot be expected to write correct syntax for columns containing embedded commas when using a comma delimited file. However, "|" delimited files work well because this character is not part of names or addresses. This tab delimited stuff is just hard to deal with.

#/usr/bin/perl use strict; use warnings; $|=1; #turns stdio buffer off so that error line order is correct while (defined (my $line = <DATA>)) { chomp $line; #removes end of line character(s) next unless $line =~ /\S/; # skip blank lines my ($motherId,$yearBirth,$individualId) = (split /\t/,$line)[4,13, +2]; $yearBirth //= ""; # DATA line 6 is a bit weird # this defines $yearBirth as "" if undefined print "UniqId=$individualId Mother=$motherId BirthY=$yearBirth \ +n"; } =Prints UniqId=1 Mother=3 BirthY=51 UniqId=2 Mother= BirthY= UniqId=3 Mother=36 BirthY=65 UniqId=4 Mother=3 BirthY=50 UniqId=5 Mother=3 BirthY=47 UniqId=6 Mother=3 BirthY= UniqId=7 Mother=3 BirthY= UniqId=8 Mother=3 BirthY=42 UniqId=9 Mother=3 BirthY=39 UniqId=10 Mother=3 BirthY=35 UniqId=11 Mother=8 BirthY=11 UniqId=12 Mother=8 BirthY=9 =cut __DATA__ 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
UPDATE:
I converted this tab delimited file to a "|" delimited file with my text editor.
I don't know what col[14] is supposed to mean? Added below as "what?".
When using a visible column delimiter, we can see issues with say Male vs Female (not a single character).
#/usr/bin/perl use strict; use warnings; $|=1; #turns stdio buffer off so that error line order is correct while (defined (my $line = <DATA>)) { chomp $line; #removes end of line character(s) next unless $line =~ /\S/; # skip blank lines my ($motherId,$yearBirth,$individualId,$what) = (split /\|/,$line) +[4,13,2,14]; $yearBirth //= ""; # DATA line 6 is a bit weird # this defines $yearBirth as "" if undefined $what //= ""; # I don't know what this is? print "UniqId=$individualId Mother=$motherId BirthY=$yearBirth W +hat=$what\n"; } =Prints UniqId=1 Mother=3 BirthY=51 What= UniqId=2 Mother= BirthY= What=999 UniqId=3 Mother=36 BirthY=65 What= UniqId=4 Mother=3 BirthY=50 What=50 UniqId=5 Mother=3 BirthY=47 What=46 UniqId=6 Mother=3 BirthY= What= UniqId=7 Mother=3 BirthY= What=999 UniqId=8 Mother=3 BirthY=42 What= UniqId=9 Mother=3 BirthY=39 What= UniqId=10 Mother=3 BirthY=35 What= UniqId=11 Mother=8 BirthY=11 What= UniqId=12 Mother=8 BirthY=9 What= =cut __DATA__ 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 |||||||||999 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|

In reply to Re: How to map data from one column based on another column in perl by Marshall
in thread 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.