in reply to Listing Files in a Directory (Translation From Shell Script)

Perl vs. tcsh?? No contest in this case. The perl version will be a lot easier and make more sense. (Run time is probably not an issue, but I expect it will run faster than the shell script + batch file.)
#!/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 );
(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.)

Replies are listed 'Best First'.
Re^2: Listing Files in a Directory (Translation From Shell Script)
by ikegami (Patriarch) on Sep 07, 2005 at 23:33 UTC
    It's the error checking that makes it longer, error checking that wasn't present in the original script. It's hard to complain that it's longer if one gets more functionality and reliability :)