Rob/James

Thanks for trying to help so far, I think i need to explain a bit more. The
file contains varying data, empty, numeric, text
data is processed in between the ordered numbers say ..1 2 3 4, the only
thing I can be certain of is,

1)  line 3 will contain number one(start of data set 1) - when checked I can
process it's data
2)  there will be a count of 3 or 4 to number 2(start of data set 2) - when
checked I can process it's data
3)  above line repeats to end
4)  end is known when number 4 has been found and processed

my idea was to process the file confirming each number found, and pushing
the line numbers into an array for further processing, I just have a mental
block on how to deal with the varying increments

Thanks
Steve






-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]
Sent: 13 October 2003 16:40
To: [EMAIL PROTECTED]
Subject: Re: design - help


Steve Massey wrote:
>
> I hear what your saying, but for this snippet I just want to
> cycle through the list, checking the number is correct either
> being   3or4 spaces between them, a print out at the end would
> be fine. My real data, has ifo on lines in between numbers, but
> the count between each number will be either 3 or 4. In reality
> if it failed the number check I will break out into a sub-
> routine.
>
> My problem is working out the loop required to achieve this, I
> have been on and off hacking at this for a week, each variation
> not quite getting there.

Then I misunderstood your original purpose. Are you verifying the
structure of the file or processing its contents?

James is right, that the first task is to defined how the lines
with sequence numbers differ from the intervening 'blank' lines
which you now say contain information. Assuming that your sequence
number lines are purely numeric, the code below may help.

Cheers,

Rob



use strict;
use warnings;

my $info;
my $sequence = 0;

while (<DATA>) {

  chomp;          # Remove record terminator
  s/\s+$//;       # and trailing whitespace
  s/^\s+//;       # and leading whitespace

  # If the record is empty or contains non-numerics
  # then it's an information line
  #
  if (length == 0 or /\D/) {
    $info++;
    die "Too many information lines" if $info > 4;
  }
  else {
    my $value = $_ + 0;   # Force to an integer value
    die "Sequence numbers out of order" unless $value == $sequence + 1;
    $sequence = $value;
    $info = 0;
  }
}




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


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

Reply via email to