chuntoon has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl use strict; use warnings; ## Declare variables and assign initial variables my $pia = 0; my $ndx = 0; my $num_recs = 0; my $in_file = "d:\\code\\temp files\\epropr_clean.txt"; my $out_file = "d:\\code\temp files\\epropr_parsed.txt"; my $arraylength; my @records; my @rec_array; my $record; ## Open input file and assign to @records open IN_FILE, $in_file || die "Couldn't open $in_file: $!\n"; while (<IN_FILE>) { @records = map split(':'), $_; } close IN_FILE; shift @records; $arraylength = @records; ## Check array contents my $count = 0; foreach (@records) { if ( $_ =~ /PROJ .{3}/ ) { $count++; } } print $count.$/; ## Determine number of items in record and place in @rec_array while ($pia < $arraylength) { if ($records[$pia + 1] =~ "Sup") { $num_recs = 20; } else { if ($records[$pia + 5] =~ m/1LT|2LT|CPT|MAJ|LTC|COL/) { $num_recs = 28; } else { $num_recs = 29; } } for ($ndx = 0; $ndx < $num_recs; $ndx++) { push (@rec_array, $records[$ndx] ); } foreach (@rec_array) { $record = shift(@records) . ";"; } $pia += $num_recs; print $num_recs . " - " . $pia . "\n"; }
If someone can guide me in the right direction, I would very much appreciate it. I have been staring at this for a couple of days now and am going code-crazy.
Thanks in advance, Chuck
I don't suffer from insanity...I revel in it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping thru an array with differing intervals
by dragonchild (Archbishop) on Dec 11, 2001 at 21:39 UTC | |
by chuntoon (Sexton) on Dec 11, 2001 at 22:13 UTC | |
by dragonchild (Archbishop) on Dec 11, 2001 at 22:40 UTC | |
|
Re: Looping thru an array with differing intervals
by Fastolfe (Vicar) on Dec 12, 2001 at 04:07 UTC |