On 12/19/2003 11:39 AM, William Martell wrote:

Thanks Randy,

Would I read the file in line by line then get the substring of data that I
need and push that onto an array pertaining to that customer.

Correct.


The question that comes to mind is that each line is different and I would
need to write something that works with each individual line.

Is this correct?

From your example, it looks as if each field is at a fixed position, i.e. each field is *always* at a fixed column position.


Example:

Qty  Desc
  1  Foo Bar
 24  Hours without sleep

in the above the Qty field always starts at column 1 (offset 0) and it has a length of 3. The desc field always starts at colum 5 (offset 4) and extends to the end of the string. So, something like the following (untested) code should work (ASSuming the format is fixed):

my @order_detail;

while (<>) {

  # extract fields
  my %item = (
    qty  => substr( $_, 0, 3 ),
    desc => substr( $_, 4 ),
  );

  # trim spaces
  while ( my ($key, $value) = each %item ) {
    $value =~ s/^\s+//;
    $value =~ s/\s+$//;
  }

  # save for later processing
  push @order_detail, \%item;
}

Regards,
Randy.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to