Paul Kraus wrote:
> I have a variable amount of text files that need to get parsed. The
> files come in groups of 6. I only need to parse files 4 5 and 6. So
> if I had 3 groups waiting to be processed then I would have to read
> through and parse 4,5,6,10,11,12,16,17,18.
> 
> The file names look like this...
> 
> 6.1.200_(1)_(9443).txt
> Date_element of group_time.txt
> 
> So I would processing all of the files for 6.1.
> Also I couldn't figure out a way to sort them easily as you will see
> me in my code so any suggestions there would be helpful also.
> 
> How can I setup a loop that will run the correct amount of times and
> only parse these files from the group. Here is my code.
> 
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use DBI;
> 
> opendir ( DH, "." ) or die ( "Could not open $!\n" );
> my @allfiles = readdir(DH);
> my %sales;
> foreach ( @allfiles ) {
>   next unless /^\d+\.\d+\.\d+_/;
>   push (@{$sales{$1}}, $_) if /^(\d+\.\d+\.\d+)_/;
> }
> 
> foreach (sort keys %sales){
>   my $salesjournals = scalar(@{$sales{$_}});
>   &processdate($sales{$_}, $salesjournals);
>   die;
> }
> 
> sub processdate {
>   my ($filenames, $salesjournals) = ( shift, shift );
>   my (%pel, %cfb, %leimkuehler, @files);
>   foreach ( @ { $filenames } ){
>     push (@files, $1 . "-$_") if /_\((\d+)\)_/;
>   }
>   @files = sort {$a <=> $b} @files;
>   foreach (@files){
>     my $tmp = $1 if s/^(\d+)-//;
>     if ( $tmp == ){
>       print "$tmp \t $_\n";
>     }
>   }
> }

        If you are only after the files which are defined by _(n)_ and you only want 
the 4,5 and 6 th elements, then you should be able to do a modulus 6 (ie, n % 6) and 
where 4,5,6 then process otherwise bypass.  If I am missing the obvious, sorry, but if 
going in a numeric sequence, the modulo should do it for you.

Wags ;)


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to