Peter Scott wrote:
On Fri, 05 Sep 2008 19:09:25 +0100, brian54321uk wrote:
I would like to test a folder full of files, and if a file contains
abc123blue or xyz357green then that file is to be deleted.
What would be the best way of achieving this please?
One way:
use strict;
use warnings;
sub delete_containing {
my ($folder, @strings) = @_;
my $regex = join '|', map { quotemeta } @strings;
unlink grep { contains( qr/$regex/, $_ ) } glob "$folder/*";
}
sub contains {
my $regex = shift;
local @ARGV = @_;
local $_;
/$regex/ and return 1 while <>;
return;
}
delete_containing( '/tmp/bar', 'abc', 'xyz' );
Just tried this, nothing happened at all.
Brian
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/