Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Why isn't the below match working even though FileMuxInternaldefs is present in $mk

#!/usr/bin/perl -w use strict; use warnings; my $folder='FileMuxInternaldefs'; my $mk='./AACBaseFileLib/common.mk: $(PROJECT_ROOT)/../FilemuxInterna +lDef'; if ($folder =~ /$mk/i) #this match failing for the give input { print "\nIN\n"; if ($folder !~ /$mk/m) { print "CASE-SENSITIVE:$mk\n"; } }

Replies are listed 'Best First'.
Re: Cont:match failing
by wind (Priest) on Mar 22, 2011 at 04:44 UTC

    Looks like you have your pattern and string reversed.

    my $folder='FileMuxInternaldefs'; my $mk='./AACBaseFileLib/common.mk: $(PROJECT_ROOT)/../FilemuxInterna +lDef'; if ($mk =~ /\Q$folder\E/i) {

    Also, there is an extra 's' at the end of $folder that won't match in $mk.

    Finally, you might consider creating an account here so that you and others can keep track of your questions more easily. It helps to be able to remember you're previous questions when answering your current ones.

    - Miller

      Hi Miller - I am totally lost,I just cant figure out what is wrong with the below code.The "IN"statement never gets printed.I am sharing my full code.Appreciate any help

      #!/usr/bin/perl -w use strict; use warnings; #use File::Find::Rule; use File::Find; use Cwd; use File::Basename; my $cwd = getcwd(); my @folders; my %seen; my (@folder_mk,$folder,$mk,$folder_present,$folder_not_present); my $CASES; my $file_name="Case_sensitivities.txt"; if ( -e $file_name ) { #print "IN $file_name\n"; #chmod 0777, $file_name or die $!; unlink $file_name or die "Unable to unlink $file_name: $!"; } open(my $FOLDERS, '+>', "dirs.log") or die $!; find(sub { push @folders, "$_\n" if -d $File::Find::name && !$seen{$_}++; print $FOLDERS "$_\n" if -d $File::Find::name && !$seen{$_}++; }, $cwd); #print "\nHeader array:@headers\n"; #my @headers = File::Find::Rule->file->name('*.h')->in($cwd); #my $header_file; foreach $folder (@folders) { next if $folder =~ /^\.+$|inc|src|arm|le-v7|config/; @folder_mk=`find.exe . -name "*.mk" -print0 | xargs -0 grep -i $fo +lder`; foreach $mk(@folder_mk) { print "\nFOLDER:$folder\n";#prints FileMuxInternaldefs print "\nMK:$mk\n";#prints ./AACBaseFileLib/common.mk: + $(PROJECT_ROOT)/../FilemuxInternalDefs/inc \ if ($mk =~ /\Q$folder\E/i) #this match failing for th +e give input { print "\nIN\n";#never enters the loop if ($mk !~ /\Q$folder\E/) #this match failing for the give +input { print "CASE-SENSITIVE:$mk\n"; } } } $mk=" "; }

        anyone has any clue ?

Re: Cont:match failing
by GrandFather (Saint) on Mar 22, 2011 at 04:50 UTC

    Because $folder doesn't match the entire match string given in $mk.

    What do you actually want to test with the match?

    True laziness is hard work