in reply to Looping thru an array with differing intervals

Lemme see if I understand what you're doing.
#!/usr/local/bin/perl use strict; use warnings; ## Declare variables and assign initial variables my $in_file = "d:\\code\\temp files\\epropr_clean.txt"; my $out_file = "d:\\code\temp files\\epropr_parsed.txt"; ## Open input file and assign to @records my @records; open IN_FILE, $in_file || die "Couldn't open $in_file: $!\n"; push @records, split(/:/, $_) while <IN_FILE>; close IN_FILE; shift @records; my $arraylength = @records; ## Check array contents my $count = 0; /PROJ .{3}/ && $count++ for @records; print $count, $/; ## Determine number of items in @record and place in @rec_array my ($record, $curr_index) = ('', 0); while ($curr_index < $arraylength) { my $num_recs = 29; if ($records[$curr_index + 1] =~ /Sup/) { $num_recs = 20; } elsif (grep { $records[$curr_index + 5] =~ /$_/ } qw(1LT 2LT CPT + MAJ LTC COL)) { $num_recs = 28; } push @rec_array, @records[0 .. $num_recs - 1]; $record = join(';', $record, splice(@records, 0, scalar(@rec_array +)); $curr_index += $num_recs; print "$num_recs - $curr_index\n"; }
All that's happening is that you're moving over elements from @record to @rec_array, then removing them from @record and moving them, joined by ';', to $record. What purpose does this serve?

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: Looping thru an array with differing intervals
by chuntoon (Sexton) on Dec 11, 2001 at 22:13 UTC
    I intend on putting the records in a file and then importing into an excel spreadsheet for my database challenged boss.

    I was having difficulty with the fact that the records are interspersed and have differing numbers of record items.

    Chuck

      So, you have a bunch of records. Some of these have 20 columns, some have 28, and some have 29. Ahhh.... this explains much.

      What you want to use is an array of arrays. Look up references in the Camel book and read for a day. :-)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.