Hi monks, ive some prroblem with my pattern mathcing problem, I am trying to print the string that containts specific characters with the position of that string in a file, but the only thng that i can get is, the location of that string in a file.
Here is my code :and the result is (if we search 'a') : found string -a- in line 2, however i expect the it prints the whole string so when i search the word that starts with 'a', it will return the word like 'air'. any help will be appriciateduse CGI; my $cgi = new CGI; print $cgi->header('text/html'); my $dir = 'C:\\inetpub\\wwwroot\\vortragsreihe_DEV\\'; my $book = $dir.'dir.txt'; opendir(DIR, $dir) or die $!; open FILE, '>'.$book; while (my $file = readdir(DIR)) { if(-f $dir.$file){ # Use a regular expression to ignore files beginning with +a period next if ($file =~ m/^\./); print FILE "C:\\inetpub\\wwwroot\\vortragsreihe_DEV\\$file +\n"; } } close FILE; closedir(DIR); open (DATEI, '<' . 'C:\\inetpub\\wwwroot\\vortragsreihe_DEV\\dir.txt') + || die "Datei nicht gefunden $!"; my @daten = <DATEI>; close (DATEI); chomp(@daten); my $number = 0; my %params = $cgi->Vars; my $string = quotemeta("$test"); foreach(@daten){ print "finding -$string- in $daten[$number]\n"."</br>" +; open(my $file, "<", "$daten[$number]") or die "Can' +t open the file: $!"; my $num = 1; while (<$file>) { if (/$string/) { my $content =~ m/(\/$string\/[a-z]*)/g; print $content; print "found string -$string- in line $num + \n"; print "<br>"; } $num++; } $number++; }
In reply to Pattern Matching problem by auhakim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |