in reply to maddening system call gzip/gunzip problems
One minor issue is that your regex,
$file !~ m/^[\w-]+(\.[\w-]+)*$/
to be acceptable: it's ending with at least zero strings comprising one dot followed by at least one word character or hyphen. That is, the (/\.[\w-]+)* portion of the regex is successfully matching a null-string. This, you could fix by replacing the final asterisk in the regex by a plus sign.cns061206
Something like this may do what you want (note: NOT TESTED)
sub zip { (my $cmd, my $dir) = @_[0,1]; my $count; if($cmd eq 'unzip') { foreach my $file (glob($dir . '/*.gz')){ # get only gzipped fi +les if(system(($cmd, $file)) == 0) { $count++; } else { warn "Could not $cmd $file\n"; } } return $count; } elsif($cmd eq 'zip') { foreach my $file (glob($dir . '/*')) { next if $file =~ /\.gz$/; next if $file =~ /\.txt$/; next unless $file =~ /(\.\w+)+$/; # which will skip files +without an extension if(system(($cmd, $file)) == 0){ $count++; } else { warn "Could not $cmd $file\n"; } } return $count; } else { warn "Unknown command $cmd\n"; } }
You could also check out Tie:Gzip, PerlIO::gzip, or IO::Uncompress::AnyInflate. Note that I've not used any of these, so I'm not endorsing any one of them.
foreach my $file (glob($dir . '/*')) {
foreach my $file (glob($dir . '/*.gz'))
my @list = glob($dir . '/*'); foreach my $file (@list) {
my @list = glob($dir . '/*.gz'); foreach my $file (@list) {
emc
At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.
—Igor Sikorsky, reported in AOPA Pilot magazine February 2003.
|
|---|