in reply to Re: Cont:match failing
in thread Cont:match failing

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=" "; }

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

    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);

        Just use the block form of if otherwise the %seen hash is being checked twice, and only the first statement would pass.

        find(sub { if (-d $File::Find::name && !$seen{$_}++) { push @folders, "$_" ; print $FOLDERS "$_\n"; } }, $cwd);