I changed my code, and it works pretty find.

#!/usr/bin/perl use CGI; my $cgi = new CGI; print $cgi->header('text/html'); if (defined $cgi->param('ok')) { 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 = $cgi->param('string'); 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/) { if (my ($match) = /(\Q$string\E\S*)/) { print "Matched '$string' in '$match' in li +ne $num"."<br />"; } # my $content =~ m/(\/$string\/[a-z]*)/g; # print $content; # print "found string -$string- in line $n +um \n"; # print "<br>"; } $num++; } $number++; } } else { print <<ENDHTML; <HTML> <BODY> <FORM name = "ariau" METHOD=GET ACTION="search.pl"> name: <INPUT TYPE=TEXT NAME="string" VALUE = ""><BR> <INPUT TYPE=SUBMIT NAME="ok" Value = "ok"> </FORM> </BODY> </HTML> ENDHTML }

but the problem is, I can not search the string that started with particular symbol, such as, i cant search something like '$test', any help will be appreciated


In reply to Re^2: Big problem in pattern matching by auhakim
in thread Pattern Matching problem by auhakim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.