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

can i just post my whole code? so you can analyze my problem? ive tried the whole solution but it still does not work

Replies are listed 'Best First'.
Re^3: Pattern Matching problem
by hdb (Monsignor) on Jun 04, 2013 at 12:49 UTC

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

      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

        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