arrays - Compare two text files in Perl -
i have several strings in 2 .txt file. both of them contain similar strings not arranged on same line number.
for example, file1.txt carmen edison molly jason damon gerard
file2.txt edison jason
i want save similar strings found in both text files (in case: edison jason) array.
without need use additional modules
#!/usr/bin/env perl use strict; use warnings; @data1 = qw( carmen edison molly jason damon gerard ); @data2 = qw( edison jason ); @data3 = (); foreach $d1 ( @data1 ) { chomp $d1; foreach $d2 ( @data2 ) { chomp $d2; if( $d1 eq $d2 ) { print "match found : $d1, $d2 \n"; push @data3, $d1; } } }
Comments
Post a Comment