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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.