Since you're using Windows I recommend you use Notepad++ or a similar programmers editor since it will help with closing brackets and parenthesis.
Also, you are likely to run into problems comparing strings with eq since filenames can have upper and lower case. Either use matching with the case insensitive modifier '//i' or 'm//i', or use the lower case function, lc(), before the compare.
use strict; use warnings; my @files = ( 'file1.txt', 'a.exe', 'my.log'); my @files2 = <DATA>; foreach(@files){ my $regex=$_; $regex =~ s/\./\\\./; # replace the '.' in file.ext # with '\.' so it will work in the match. print "\n\tuse $regex as the regex\n"; foreach my $file2(@files2){ chomp $file2; print "---", $file2, "\n"; if ($file2 =~ /$regex/i){ print "\tmatched with //i...\n"; if ($file2 ne $_){ print "\tbut not with string compare.\n"; } else {print "\tand with string compare.\n";} } } } #this one was missing __DATA__ File1.txt A.exe B.ext my.log
updated; fixed some goofy bugs
In reply to Re: Need help with comparison code
by Gulliver
in thread Need help with comparison code
by sowais
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |