in reply to Looping thru an array with differing intervals
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?#!/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"; }
------
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 | |
by dragonchild (Archbishop) on Dec 11, 2001 at 22:40 UTC |