The code below works. Thanks for the pointers on the unless loop, haven't used that before. It appears that the limitation I was running into was only on my Mac perl config; the code works fine under linux.

#!/usr/bin/perl -w
#open directory and load contents into hash
use strict;
my $dir="/test/directory";
opendir(DIR, $dir) or die "cant opendir $dir: $!";
while($_=readdir(DIR)) {
  unless(/^\./) {
    unlink($dir.'/'.$_);
    print "unlinking $_...\n";
  }
}
closedir(DIR);

Thanks for the assist. I'll run this by an Apple engineer and see why my Panther perl config didn't like it.

Charles

On Jan 4, 2004, at 9:38 PM, Shawn McKinley wrote:


#!/usr/bin/perl -w #open directory and load contents into hash use strict; my $dir="/test/directory"; opendir(DIR, $dir) or die "cant opendir $dir: $!"; while($_=readdir(DIR)) { unless(/klee/) { unlink($dir.'/'.$_); print "unlinking $_...\n"; } }} closedir(DIR);

However, if you are only wanting to skip files that start with
'.'s, you can swap out:

if(/klee/) {

with

unless(/^\./) {

This should be faster since you are only checking the start
of each file...

Shawn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to