John W. Krahn wrote:
> Rob Dixon wrote:
>> Rob McGinness wrote:
>>> die unless chdir
>>> "/cert/ImpactServer-5_4/cl9/ctrl_sfm9/sfm9_sched/archives";
>>>
>>> die unless opendir DIR, ".";
>> I suggest you write something like the program below.
>>
>>
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>>
>> my $dir = "/cert/ImpactServer-5_4/cl9/ctrl_sfm9/sfm9_sched/archives";
>>
>> my @files = do {
>>   opendir my $dh, $dir or die $!;
>>   grep /^Completed\.archive\.\d{1,4}$/, readdir $dh;
>> };
>>
>> @files = sort grep -M > 7, @files;
> 
> The OP chdir()ed to the directory in question so the files were in the 
> current directory, however your code does not so the -M test will not 
> work unless you prepend the directory name to the file name:
> 
> @files = sort grep -M "$dir/$_" > 7, @files;
> 
> 
> Also, why not put both tests in the first grep:
> 
> my @files = do {
>    opendir my $dh, $dir or die "Cannot open '$dir' $!";
>    grep /^Completed\.archive\.\d{1,4}$/
>         && -M "$dir/$_" > 7, readdir $dh;
> };
> 
> 
>> foreach (@files) {
>>   system 'compress', '-v', $_;
>> }
> 
> You should verify that system worked correctly:
> 
> foreach (@files) {
>    0 == system 'compress', '-v', $_ or die "system 'compress' failed: $?";
> }

Thanks John

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to