> [EMAIL PROTECTED] wrote:
> > Hi All,
> > 
> > I want to read contents of a dir, filtered, into a hash.  I 
> have this:
> > 
> > #/usr/local/bin -w
> > use strict;
> > my (@ARRAY, %TEST, $FILTER) = "";
> > 

You may want to make sure $FILTER isn't anythign harmful here:
For instance what if Someone enters
whatever" someother evil command "sucker

You might want to try the File:: modules and/or use Perl functions :

use File::Slurp;

my @files = read_dir('/foo/bar');
my @ARRAY = grep /$FILTER/, @files;
 for(@ARRAY) { my @fileinfo = stat("/foo/bar/$_"); }

Or to make it shorter and sexxier:
        my %files;
 for(grep(/$FILTER/, read_dir('/foo/bar'))) { 
        my @fileinfo = stat("/foo/bar/$_"); 
        #ADD @fileinfo the file hash you could even do

        (${$files{$_}}{'dev'}, ${$files{$_}}{'ino'}, ${$files{$_}}{'mode'}, etc..) =  
stat(...);

 }# perldoc -f stat

Now if someone tries to put in evil $FILTER no system damage will be done, at worst, 
no files will match.
AND $FILTER can be a Perl regex, even better!!


> > print "Enter filter:";
> > $FILTER = <STDIN>;
> > chomp $FILTER;
> > @ARRAY = ` ls -l /foo/bar | grep "$FILTER" `;
> > for (@ARRAY) {
> > chomp;
> > }
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to