> I have the following line in a text file 
> 
> Total  3250     5     0     0     0     0      8797    17     
> 0     0     0   
>   0      9264    18     0     0     0     0      9207    14   
>   0     0     0 
>     0      6925    10     0     0     0     0
> 
> (this is the entire line, but  it's just wrapped)
> 
> I have a regex that will get the values after the four digit 
> numbers( (5, 17, 
> 18, 14 and 10).....it is
> 
> ^Total\s+\d+\s+(\d+)(?:\s+\d+){5}\s+(\d+)(?:\s+\d+){5}\s+(\d+)
> (?:\s+\d+){5}\s+(\d+)(?:\s+\d+){5}\s+(\d+)
> 
> (they won't always be four digit numbers so I can't put that 
> in my regex) 
> 
> Now, this is great, when I have 5 numbers that I need to 
> retrieve..... but if 
> the line looked like
> 
> Total  3250     5     0     0     0     0      8797    17     
> 0     0     0   
>   0      9264    18     0     0     0     0 
> 
> then there wouldn't be a match.  Anyone have ideas of how 
> this can be adapted 
> to say that if there are at least 2 sets of numbers (a set 
> would be 3250 5 0 
> 0 0 0 - in the case above there are 3 "sets" and at the top 
> there are 5) and 
> a maximum of 6 sets of numbers it would get the number in the second 
> place....in this case it would get 5, 17 and 18.

You could use an array, like so:

my @second_places = ();
while(<FILE>) {
  chomp;
  my @values = split /\s+/;
  my $i = 2;
  while(defined $values[$i]) {
    push @second_places,$values[$i];
    $i += 6;
  }
}

This splits your line on whitespace and saves every sixth element, if it
is defined, starting with the third one.

HTH,

 -dave



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

Reply via email to