RE: design - help

From: Steve Massey (steven_massey_at_0800dial.com)
Date: 10/13/03


To: <beginners@perl.org>
Date: Mon, 13 Oct 2003 17:04:13 +0100

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:rob@dixon.port995.com]
Sent: 13 October 2003 16:40
To: beginners@perl.org
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: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


Relevant Pages

  • Re: Dinis theorem
    ... Let X be compact and be a sequence of ... >> continuous real-valued functions on X which converges pointwise, ... > the intersection of all K_n is empty. ... > large enough and saying that K_n is empty is the same thing as saying ...
    (sci.math)
  • Re: double blank lines for index
    ... > and Set 2 are empty _before_ the double blank lines. ... Just like any sequence of at least one blank character ... you have to make sure each dataset consistes of at least one ...
    (comp.graphics.apps.gnuplot)
  • RE: I support PEP 326
    ... > Calling min with no arguments need not be the same as calling it with an ... > the empty function call return something arguably strange... ... lowest element of an empty sequence. ... sequence, and if that sequence is empty, you get an exception. ...
    (comp.lang.python)
  • Different Color
    ... And if and other sequence id found on that row to assign another color. ... Then to check and assign the next row until the range is empty. ... My question above rests on two of the same colors. ... Prev by Date: ...
    (microsoft.public.excel.programming)
  • Re: Real Number Paradox?
    ... >>> that the elements of A all have a finite decimal expansion. ... the limit of a constant sequence is the constant. ... > By |S| I mean the cardinality of S. So you have a sequence of sets X_1, ... probably be the empty set with a sensible definition. ...
    (sci.math)