gvs_jagan has asked for the wisdom of the Perl Monks concerning the following question:
How to access the file content chracter by character , i have tried using to do with the "do" function and $/ , but the problem is that in this manner a pattern is looked for only once .
here is the url http://83.138.185.127/cgi-bin/search3.cgi
iam pasting the code below .
regards , jagan
----------------------------------------------------------
#!/usr/bin/perl -T use CGI qw(:standard); use CGI qw(warningsToBrowser fatalsToBrowser); my $file1 = param("fil1"); my $key1 = param("phr1"); my $st1 = param("str1"); print header, start_html(-title=>"Searching for a pattern in a file" , + -bgcolor=>"#cccccc"); h1("Searching for a pattern in a file" ); if(param()) { my $file1 = param("fil1"); my $key1 = param("phr1"); my $st1 = param("str1"); my $i =0 ; open(FILE , "$file1") or die("could not open the file $!\n"); while(<FILE>) { my $st1 = do{local $/ , <FILE>}; if($st1=~ m/$key1/) { $i++; print p("The pattern <b> $key1</b> has been found <b> $i</b> times.\n" +); } else { print p("The pattern <b> $key1</b> has not been found.\n"); } print p "<a href=http://83.138.185.127/cgi-bin/search3.cgi> Try Again +</a> " ; } } else { print hr() , start_form(); print p("Enter the file name you wish to make a search into" , popup_m +enu("fil1" , ['file1' , 'file2' ,'file3' ,'file4'])); print p("Enter the key word you wish to search for " , textfield("phr1 +" , "")); print p(submit("go") , reset("clear")); print end_form() , hr(); } end_html();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: acessing the contents of a file character by character
by Fletch (Bishop) on Jun 10, 2005 at 11:53 UTC | |
|
Re: acessing the contents of a file character by character
by tlm (Prior) on Jun 10, 2005 at 12:22 UTC | |
|
Re: acessing the contents of a file character by character
by Limbic~Region (Chancellor) on Jun 10, 2005 at 12:29 UTC | |
|
Re: acessing the contents of a file character by character
by jpeg (Chaplain) on Jun 10, 2005 at 12:43 UTC | |
|
Re: acessing the contents of a file character by character
by TedPride (Priest) on Jun 10, 2005 at 17:12 UTC |