in reply to Re: Big problem in pattern matching
in thread Pattern Matching problem

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

Replies are listed 'Best First'.
Re^3: Big problem in pattern matching
by choroba (Cardinal) on Jun 05, 2013 at 07:56 UTC
    Remove
    if (/$string/) {

    or change it to

    if (/\Q$string\E/) {
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      and do you know how to make it case insensitive? I tried to change it with (/(\Q$string\E\S\i*)/) but it does not work -,-
        Study the documentation:
        /(\Q$sting\E\S*)/i
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ