SysAdm has asked for the wisdom of the Perl Monks concerning the following question:

Here's my problem... I have a directory I'm reading, and the files listed in the directory look like 3467534.dat. I have included an index.htm file in the same directory, but I want to SKIP any index.htm files from being read by this sub..

sub read_item_file { my ($cat, $item) = @_; return '' unless ($cat) and ($item); &oops('The category may not contain any non-word characters, such +as a space or symbol.') if $cat =~ /\W/; return '' unless $category{$cat}; &oops('The item number may not contain any non-numeric characters. +') if $item =~ /\D/; return '' unless 0||#1>>noconfuse(ea;-) open FILE, "$config{'basepath'}$cat/$item.dat" or &oops("Could not + open project file."); my ($title, $counter, $desc, @bids) = <FILE>; close FILE; chomp ($title, $counter, $desc, @bids); return ($title, $counter, $desc, @bids); }


This line seems to be the problem...
open FILE, "$config{'basepath'}$cat/$item.dat" or &oops("Could not ope +n project file.");


I need to ignore index.htm from being read at all...

Thanks in advance, I was hoping to use the index.htm file as a security issue to prevent people from typing in the URL and looking at the contents in the directory...

_____SysAdm

Replies are listed 'Best First'.
Re: Ignoring index.htm in a directory
by mr.nick (Chaplain) on May 19, 2001 at 19:06 UTC
    Hm, I'm not sure exactly what you mean, but if you are interested in gathering a list of files from a directory, but exclude "index.htm" from the list, I'd use something like this:
    my @files=grep $_ ne 'index.htm',<the/directory/*>;
Re: Ignoring index.htm in a directory
by thpfft (Chaplain) on May 19, 2001 at 20:18 UTC

    Firstly, as mr nick observes, your best option is to exclude index.htm at the point where you read the directory, or whatever else is involved before you invoke this sub.

    But then i'm a little confused, as this script won't try and read index.htm anyway. It appends .dat to the name you pass to it, so it I suppose it might try and read index.htm.dat if you're coming from an earlier readdir, but then it will just go &oops in the proper way.

    Please reply if there's a particular problem i haven't understood, but it seems to me that you're basically fine.

    Except there are much better ways to protect the directory from passers-by, anyway. A basic through-obscurity approach like this is pretty shaky, especially if the cats and ids are appearing on a site somewhere. The simplest alternative would be to put the data outside the web root, or use an .htaccess file to exclude everyone.

    Your .htm suggests that you're on windows. I guess IIS must have some equivalent directory-level access-control mechanism? I tried looking on google but it kept offering me MCSE courses so i fled.

      Thank you for your response... I ended up using .htaccess/.htpasswrd

      thanks again...

      ______SysAdm