in reply to Grep failing

Based off your very limited description, I'm surmising that $mk contains a return delimited list of folders and you're trying to determine if $folder is present.

As davido already pointed out, grep is not what you need for this because that is meant only for array operations. If you're just working on a scalar, you can do the test directly. Secondly, based off your regex, I suspect your problem is you're not using the 'm' modifier which would make it so ^ and $ matched the beginning and end of any line within the text, not just the start and end of the string.

Here's an example that does match like you want

my $mk = <<'END_LIST'; /foo/bar /foo/baz /eep/foo/bar /epp/foo/baz /biz /baz/foo/bar END_LIST my $folder = '/foo/baz'; my $folder_present = $mk =~ /^\Q$folder\E$/im; print "$folder_present"; # Prints 1

- Miller

Replies are listed 'Best First'.
Re^2: Grep failing
by Anonymous Monk on Mar 21, 2011 at 23:55 UTC

    Does anyone have any idea why the below if condition is failing for the given input?

    $folder:FileMuxInternaldefs $mk:./AACBaseFileLib/common.mk: $(PROJECT_ROOT)/../FilemuxInternalDef +s/inc \ if ($folder =~ /$mk/i) #this match failing for the give +n input { print "\nIN\n"; if ($folder !~ /$mk/m) { print "CASE-SENSITIVE:$mk\n"; } }

      Probably for the same reason when you asked here, FOR LOOP not entered.

      Your code does not actually run because of this nonsense

      $folder:FileMuxInternaldefs $mk:./AACBaseFileLib/common.mk: $(PROJECT_ROOT)/../FilemuxInternalDef +s/inc \