Fellow Monks. I have ran into a problem with the task at hand. The script below is designed to read a file and take what is in the first column and if it matches the fifth column of the second to print out its corresponding row of data.

File1 Sample Data Input

name 17 name2 14 name3 14

File2 Sampe Data Input

1 2 3 4 name2 6 7 8 9 10 11 12 13 14 15 1 77 5 4 name2 6 9 8 9 10 11 12 13 14 15 1 2 3 4 name5 6 7 8 9 10 11 12 13 14 15

Desired Output

1 2 3 4 name2 6 7 8 9 10 11 12 13 14 15 1 77 5 4 name2 6 9 8 9 10 11 12 13 14 15

code

open(FILE1, $ARGV[0]) or die "Cannot open the file: $!"; my $name while(my $line = <FILE1>) { my @data = split(" ", $line); $name = "$data[0]"; } open(FILE2, $ARGV[0]) or die "Cannot open the file: $!"; while(my $line = <FILE2>) { my @data2 = split(" ", $line); my $element = "$data2[4]"; if ($element = $name) { print "$data2[0]\t$data2[1]\t$data2[2]\t$data2[3]\t$data2[4]\t$dat +a2[5]\t$data2[6]\t$data2[7]\t$data2[8]\t$data2[9]\t$data2[10]\t$data2 +[11]\t$data2[13]\t$data2[14]\n"; } } close FILE1; close FILE2; exit;

the first part of the script prints the "$data[0]" works fine. I even tested it by itself by asking it to print "$name". The second part where I assigned "$data[0]" to the variable $name is what is giving me issues. I don't think it is recognizing it and not fulfilling the if then statement before the print. Am I approaching this incorrectly through

pseudo code

if column 5 FILE2 = column 1 of FILE1

print row


In reply to Table Matching by gghelpneeded

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.