Link to home
Start Free TrialLog in
Avatar of paulwhelan
paulwhelan

asked on

search all files in dir

id like a perl script that searches all the files in a dir

if what the users enters in the search box is in any file
or all files it will return a link to that file which can be clicked
on so the file can be viewed

thanks
Avatar of olthoff
olthoff

opendir(DIR, "dirtoopen");
foreach ($File = readdir(DIR)) {
  open(FILE, $File) || die("Can't open file\n");
  while (<FILE>) {
    if (m/$UserEntry/) { push(@Files, $File);
  };
  close(FILE);
};
close(DIR);

#### Now generate the HTML
Avatar of paulwhelan

ASKER

i cant seem to get this to work
can u post a working version
thanks
paul
Avatar of ozo
while( defined($File = readdir(DIR)) ){
#or
foreach $File (readdir(DIR) ){
where does that line go in?
can someone repost the full code?
thanks
paul
my $File;
opendir(DIR, "dirtoopen");
foreach $File (readdir(DIR)) {
  open(FILE, $File) || die("Can't open file\n");
  while (<FILE>) {
    if (m/$UserEntry/) {
       push(@Files, $File);
    };
  };
  close(FILE);
 };
close(DIR);
i cant seem to follow this code
can someone repost the html and perl to search all files in a dir?
thanks
paul
ASKER CERTIFIED SOLUTION
Avatar of maxkir
maxkir
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
could u put in some options like
case sensitivity and max number of results and anything else that might be of interest
thanks
Case insensitive serach:
m/$UserEntry/i

Case sensitive serach:
m/$UserEntry/

Max number of results is achived via simple counter in
foreach $File cycle with 'last;' command when counter exceeds maximum amount of files.

Sorry, but I'm not going to write the whole program for you.