in reply to maddening system call gzip/gunzip problems

One minor issue is that your regex,

$file !~ m/^[\w-]+(\.[\w-]+)*$/

will, if I read the regex correctly, consider this:
cns061206
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.

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.


NOTE: akin to what idsfa said about readdir, the glob calls should be probably be moved out of the foreach loop control statements. That is, replace:
foreach my $file (glob($dir . '/*')) {

and
foreach my $file (glob($dir . '/*.gz'))

with
my @list = glob($dir . '/*'); foreach my $file (@list) {

and
my @list = glob($dir . '/*.gz'); foreach my $file (@list) {

respectively.

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.