in reply to array matching
Here is some half hearted sample code. In this case I assume you have read your lines for each file into @file1_lines and @file2_lines. I also assume you've run chomp on the arrays. This is a reasonable approach if you know your files are a manageable size and you don't mind loading them entirely into memory. In practice I would recommend a while loop to read any file of unknown size whenever possible.
My guess, given your expected output, is that when you see any of the strings in file2 in file1, you would like to delete that string and the rest of the line in file1. I've tried to be extra verbose here in showing this replace, and pushing the results to @output_array.
$replace_pattern is a pattern built from the strings in file2 to match any of those strings to the end of the line. The sample code produces your desired output sample.
my @file1_lines = qw( xxtcgtatccgaggga cgcgcgggggagg jjsjjjjsjjjdtcgtat aaaaaaacccaaan ggtcgtatffaadda gggctggalllslllssdkk ); my @file2_lines = qw( tcgtat gctgga ); my $replace_pattern = join('.*|', @file2_lines) . '.*'; my @output_array; for my $line (@file1_lines) { my $output_line = $line; $output_line =~ s/$replace_pattern//; push @output_array, $output_line; } say for @output_array;
|
|---|