auhakim has asked for the wisdom of the Perl Monks concerning the following question:
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++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pattern Matching problem
by choroba (Cardinal) on Jun 04, 2013 at 12:06 UTC | |
|
Re: Pattern Matching problem
by hdb (Monsignor) on Jun 04, 2013 at 12:05 UTC | |
by auhakim (Novice) on Jun 04, 2013 at 12:46 UTC | |
by hdb (Monsignor) on Jun 04, 2013 at 12:49 UTC | |
by auhakim (Novice) on Jun 04, 2013 at 12:54 UTC | |
by hdb (Monsignor) on Jun 04, 2013 at 13:16 UTC | |
| |
by marto (Cardinal) on Jun 04, 2013 at 12:59 UTC | |
| |
by hdb (Monsignor) on Jun 04, 2013 at 14:32 UTC | |
|
Re: Big problem in pattern matching
by kennethk (Abbot) on Jun 04, 2013 at 14:38 UTC | |
by auhakim (Novice) on Jun 05, 2013 at 07:49 UTC | |
by choroba (Cardinal) on Jun 05, 2013 at 07:56 UTC | |
by auhakim (Novice) on Jun 05, 2013 at 08:20 UTC | |
by choroba (Cardinal) on Jun 05, 2013 at 08:23 UTC |