in reply to Re^2: Pattern Matching problem
in thread Pattern Matching problem

If it is not tons of lines...
It would also be good if it runs standalone without requiring any extra inputs, files etc.

Replies are listed 'Best First'.
Re^4: Pattern Matching problem
by auhakim (Novice) on Jun 04, 2013 at 12:54 UTC
    I hope you dont considered those code as ton of lines codes. and the input file is just the list of directory which should be scanned

      I have tried to clean it up a bit but no guarantee as I cannot run it...

      • I have changed the loop over the files to eliminate $number.
      • I also eliminated $num as $. already contains the line number.
      • I changed the line with my $content ... to catch the match rather than comparing $content with the pattern.
      • $test is not defined anywhere in your code fragement.
      • You test for match with $string in the if clause, but then you populate $content based on a different match: /$string/[a-z]*. If the former matches the latter might still fail! This might cause your problem.

      # what is in $test ? Not specified. my $string = quotemeta("$test"); foreach my $filename (@daten){ print "finding -$string- in $filename\n"."</br>"; open(my $file, "<", $filename) or die "Can't open the file: $!" +; while (<$file>) { if (/$string/) { print; # NEW STATEMENT my ($content) = m/(\/$string\/[a-z]*)/g; # different match +, might fail print $content; print "found string -$string- in line $. \n"; # $. is the +line number print "<br>"; } } }

      UPDATE: added a print statement to check hypothesis

        the $test here recognized as a string, so the program will find the string that contain $test

        yup sorry, im in my deadline. I'll make sure that my next post match the quality standard of the post

      If $string is "a", then \/$string\/[a-z]* does NOT match "air". It would match "/a/ir".

      $string = "a"; print "success 1\n" if "air" =~ /$string/; print "success 2\n" if "air" =~ /\/$string\/[a-z]/; print "success 3\n" if "/a/ir" =~ /\/$string\/[a-z]/; print "success 4\n" if "air" =~ /$string[a-z]/; # UPDATE