Rob McGinness wrote: > Hi Everyone, > > I am very new to perl so I am not sure why my script is only partially > working, so here is the problem. > > I am trying to compress files with certain filenames that are older than > 7 days. But when running the script it only compresses the first file > only and I get errors on the rest. I know it's not a permissions issue > with the files because when I run the script a second time it will > compress the next file successfully and get errors on the remaining > files. > > I am using AIX operating system. > > Any help would be greatly appreciated. Thanks in advance. > > ERROR Messages > > sh[2]: Completed.archive.4: 0403-006 Execute permission denied. > > sh[3]: Completed.archive.5: 0403-006 Execute permission denied. > > > Script > > #!/usr/bin/perl
You should always use strict; use warnings; at the start of your program. That way many simple mistakes will become obvious. > > > > die unless chdir > "/cert/ImpactServer-5_4/cl9/ctrl_sfm9/sfm9_sched/archives"; > > die unless opendir DIR, "."; > > > > my @list1 = `ls Completed.archive.[0-9]`; # list > of single digit archive files. > > my @list2 = `ls Completed.archive.[0-9][0-9]`; # list > of double digit archive files. > > my @list3 = `ls Completed.archive.[0-9][0-9][0-9]`; # list > of triple digit archive files. > > my @list4 = `ls Completed.archive.[0-9][0-9][0-9][0-9]`; # list > of quadruple digit archive files. > > my @list = sort "@list1"."@list2"."@list3"."@list4"; # > combined list of 1,2,3,4 excluding .Z ext. > > my @zfile = grep(7 < -M, @list); # list > of combined 1,2,3,4, older than 7 days. > > foreach (@zfile) { > > > > system "compress -v ".$_ ; # AIX command to compress files. > > #print $_ ; # print to screen. > } > > closedir DIR; It's best to write your application in Perl rather than shelling out to other utilities. There are two problems here: firstly the output from `ls...` commands has trailing newline characters at the end of each line, and secondly your statement my @list = sort "@list1"."@list2"."@list3"."@list4"; concatenates the contents of the four subsidiary lists into a single string and assigns that one value to @list. Try print $list[0]; to see that. There are many Perl modules available for compressing files (zip, lha and rar are all available, for instance) but nothing that I know of that will create an IBM compressed file, so as far as I know your only option is to shell out to the compress utility. Take a look at http://search.cpan.org/search?query=archive%3A%3A&mode=module if you're interested. I suggest you write something like the program below. HTH, Rob #!/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; foreach (@files) { system 'compress', '-v', $_; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/