in reply to print data with matching id from two different files

Hello mao9856,

One possible way it to store keys of both files based on id e.g. file keys qw(ABS0056 ABS0057 ABS0058) etc as you read your file push them into an array. Create a hash from the second file with key the id and value the name e.g. $hash{"ABS0056"} = "SAM"; while you read the file.

Then simply compare keys and find the common ones, iterate over the hash with the common keys remove the ones that are not common and voila. :D

Hope this helps you to proceed. Show us the effort of resolving your problem not just this is what I want to do do it for me.

Update: Module to compare arrays List::Compare.

Update2: Maybe this small sample of code will get you to the right direction. This is more or less 3/4 of the solution. There are many ways to approach your problem but this is one out of them. Sample of code below:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub cleanString { my ( $str ) = @_; my ( $first , $second ) = split( / / , $str ); return substr( $second , 1 , length($second) -2 ); } my $File1 = 'file1.txt'; open (my $fh1, "<", $File1) or die "Error opening file1: $!\n"; my @keys; my $keyRef; while (<$fh1>) { chomp; next unless $_ ne ''; $keyRef->{$_} = 1; push @keys, $_; } close $fh1 or warn "Could not clode file1: $!\n"; # print Dumper $keyRef; # print Dumper \@keys; my $File2 = 'file2.txt'; open (my $fh2, "<", $File2) or die "Error opening file2: $!\n"; my %hash; while (<$fh2>) { chomp; next unless $_ ne ''; my @elements = sort( map { s/^\s+//; # strip leading spaces s/\s+$//; # strip trailing spaces $_ # return the modified string } split ';', $_ ); # print Dumper \@elements; $hash{cleanString($elements[0])} = cleanString($elements[1]); } close $fh2 or warn "Could not clode file1: $!\n"; print Dumper \%hash; __END__ $ perl test.pl $VAR1 = { 'ABS0059' => 'JOE', 'ABS0060' => 'MARY', 'ABS0057' => 'BILL', 'ABS0061' => 'STEPHAN', 'ABS0065' => 'RONIE', 'ABS0056' => 'SAM' };

BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!