in reply to Cont:match failing

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

Replies are listed 'Best First'.
Re^2: Cont:match failing
by Anonymous Monk on Mar 22, 2011 at 05:22 UTC

    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 ?

        Finally,I think I know why ,am pushing $_\n to array,a new line,that is the reason it's not matching

        But I have one question,in the below code which ever is present first push or print is working,the second line is not coming into picture,is there a way I can push to array and print to a file at the same time?

        open(my $FOLDERS, '+>', "dirs.log") or die $!; find(sub { push @folders, "$_" if -d $File::Find::name && !$seen{$_}++; print $FOLDERS "$_\n" if -d $File::Find::name && !$seen{$_}++; }, $cwd);