http://www.perlmonks.org?node_id=1004325


in reply to File existance check failure

Got restless ...

Ok, Took the advice and made a few changes ... :)

I could not get the "when" usage to work!
Running at least Perl v5.16.0
Tried as described in perlsys

So the latest version.

#!/usr/bin/perl use strict; use warnings; # ** # * BCE 42. # * Read a list of file names from a file and delete them. # ** # # ** # * It is what it is, you can do with it as you please. [with respect +, leave the credits] # * # * Just don't blame me if it teaches your computer to smoke! # * # * -Enjoy # * fh :)_~ # ** # # ** Example clean.list # * : Everything after a : and blank lines are ignored # * : Wildcards are valid, be careful. # * : # * # * install_manifest.txt # * cmake_install.cmake # * CMakeCache* # * examples/*.a # ** use File::Basename; my $Prog = "cmake -E"; my $RmDir = "remove_directory"; my $RmFile = "remove -f"; my $RmLink = "remove -f"; sub runCommand { return `$Prog $_[0] \"$_[1]\"` if $_[0] && $_[1]; return -1; } sub cleanup_Link # non Win32 { print "Deleting Link: $_[0]"; runCommand($RmLink, $_[0]); print " ... Deleted!" if not -l $_[0]; print "\n"; } sub cleanup_Dir { print "Deleting Dir : $_[0]"; runCommand($RmDir, $_[0]); print " ... Deleted!" if not -d $_[0]; print "\n"; } sub cleanup_File { print "Deleting File: $_[0]"; runCommand($RmFile, $_[0]); print " ... Deleted!" if not -f $_[0]; print "\n"; } sub cleanup { for (glob qq("$_[0]")) { cleanup_Link($_) if -l; # non Win32 cleanup_Dir ($_) if -d _; cleanup_File($_) if -f _; } } sub main { my $Dir = dirname(__FILE__); open(FILE, "$Dir/clean.list") or die("Unable to open file: $Dir/cl +ean.list."); my @Data = <FILE>; close(FILE); foreach my $line (@Data) { next if $line =~ /^$/; # skip blank lines next if $line =~ /:/; # skip comment lines with ':' (colon) +in them chomp $line; # trim the newline cleanup($line); } } main();

Critiques ??
Comments ??
Suggestions ??
Improvements ??

Thanks

-Enjoy
fh : )_~