CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
my search

 



billydean
Deleted

Mar 24, 2000, 2:14 PM

Post #1 of 5 (1055 views)
my search Can't Post

Hi I am trying to write a simple search for a file, but it will only find certain text. I only use single words like "al", and i know that that word is in more than one file.Is the method I used bad?

here it is:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/perl/bin/perl
$in=<STDIN>;
$path="/windows";
opendir(DIR, $path);
@a=grep(/./, readdir(DIR));
closedir(DIR);
for($d=0;$d<=$#a;$d++)
{$file=$a[$d];$filepath="$path/$file";open(FILE, $filepath);@$file=<FILE>;close(FILE);
for($e=0;$e<=$#$file;$e++)
{if ($$file[$e]=~/$in/i)
{print "$file\n"}}};
END</pre><HR></BLOCKQUOTE>


billydean
Deleted

Mar 25, 2000, 6:22 PM

Post #2 of 5 (1055 views)
Re: my search [In reply to] Can't Post

should this be posted in a different section?


Cure
User

Mar 25, 2000, 6:43 PM

Post #3 of 5 (1055 views)
Re: my search [In reply to] Can't Post

Hi

Im kinda lost here-> Your trying find .txt files that contain certain words in a directory?(is this right)


Cure


billydean
Deleted

Mar 25, 2000, 9:10 PM

Post #4 of 5 (1055 views)
Re: my search [In reply to] Can't Post

Im sorry for not explaining my problem more. I figured it out messing around, that the <STDIN> puts a \n after what ever the user types. And adding the line $in=~/\n//; works.


Cure
User

Mar 25, 2000, 9:35 PM

Post #5 of 5 (1055 views)
Re: my search [In reply to] Can't Post

Hi

The input_record_seperator by default is a newline.

So in your case, you could use the chomp function.

Example::

$in=<STDIN>;
chomp;(this will get rid of the newline character.)


Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives