Ok...still trying to parse my file.
This is what I have so far: I have cleaned my original input file so that it is now 1 horrific line of colon seperated values.
Now to the current problem: I need to loop through the array with differing intervals based on values encountered in specific record spots. I get through one iteration and then it gets locked into a screwball scenario where it never changes the value again and then begins harrassing me about unitialiazed values in m//. I can't attach example records due to privacy act and all that, but the code is below.

#!/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.


In reply to Looping thru an array with differing intervals by chuntoon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.