I want to look for specific lines in tobecompared file,which are not available in my SourceFile.I have a mistake that I cant find
open INPUT, "SourceFile";
@input = <INPUT>;
close INPUT;
open FILE, "tobecompared";
while (<FILE>){
if (/>/) {
push(@array, $_);
}
}
foreach $temp (@array) {
$temp =~ s/>//;
$temp =~ s/\s.*\n$//g;
if (@input !~ $temp){
print $temp."\n";
}
}
close FILE;
In you code
The variable
@inputis evaluated in scalar context, which returns the number of elements in@input. So you print you line unless the number of lines in SourceFile is matched by any line in tobecompared interpreted as a regular expression after some mangling.Except for any mangling you need to do, the standard solution to the problem “print all lines in fileA which isn’t in fileB” is to read all lines in fileB into hash keys and then use exists. That is:
You can of course add any mangling before adding lines to %seen and before testing for existence in %seen.