in reply to Table Matching

In your example $name will contain the value of the last line of file1 only, as you overwrite it on each pass through the loop. I suspect you want all the names in file1, so you can store them in a hash instead. Also, if ($element = $name) will always be true, what you need is if ($element eq $name). If I am right about you wanting to check all file1 names then you could do:
use strict; use warnings; use Data::Dumper; my $file1 = $ARGV[0]; my $file2 = $ARGV[1]; my %names; open( my $fh1, '<', $file1 ) or die "Cannot open $file1: $!"; while (my $line = <$fh1>) { my @data = split(" ", $line); $names{ $data[0] }++; } close( $fh1 ); # have a look to see what is in %names print Dumper( \%names ); open( my $fh2, '<', $file2 ) or die "Cannot open $file2: $!"; while (my $line = <$fh2>) { my @data2 = split(" ", $line); my $element = $data2[4]; if ( $names{ $element } ) { print join("\t", @data2 ), "\n"; } } close( $fh2 );

Replies are listed 'Best First'.
Re^2: Table Matching
by gghelpneeded (Novice) on Jul 18, 2015 at 00:02 UTC

    when dealing with two files (as a general concept) should one be thrown into a hash, then that hash be used to analyze it? Because initially I thought a simple comparison of each column would suffice. But as you pointed out my loop only left me with the value of the last line.