(I hoped to say the perl version would be shorter, but that would depend on how you measure script length -- the perl script above is more lines, but fewer characters compared to your shell script, and it does not require the creation of a separate batch file to be run at some other time. And of course, the perl could be shortened to fewer lines.)#!/usr/bin/perl use strict; my %files; # load %files with names of all images on disk for my $disk (qw/F G H/) { if ( open( I, $disk."dir.txt" )) { while (<I>) { next unless ( /_/ ); my $name = "$disk:\\backup\\" . ( split )[4]; $files{$name} = undef; } } else { warn "unable to open dir.txt for $disk: -- $!\n"; next; } } # eliminate hash elements in %files if Netbackup thinks they are on di +sk if ( open( I, "cat.txt" )) { while (<I>) { if ( /([FGH]:\\backup\\)/ ) { my $path = $1; s/\Q$path\E/*/g; my $name = $path . ( split /\*/ )[1]; delete $files{$name}; } } } else { # best to stop here if that last open failed: die "open failed for cat.txt: $!"; } # delete files that are left in the hash unlink for ( keys %files );
In reply to Re: Listing Files in a Directory (Translation From Shell Script)
by graff
in thread Listing Files in a Directory (Translation From Shell Script)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |