Here's one way that you should be able to adapt for your needs.

#! perl -sw use strict; my @data = <DATA>; my ($type3total, $type4total) = (0,0); my $state = ''; for (@data) { chomp; my ($part1, $part2) = split; if ($state eq "type4" && $part1 eq "3") { process( $type3total, $type4total ); ($type3total, $type4total) = (0,0); } $state = "type$part1"; $type3total += $part2 if ($part1 == 3); $type4total += $part2 if ($part1 == 4); die "array contains a type 7 record\n" if $part1 == 7; } process( $type3total, $type4total ); sub process { my ($type3, $type4) = (shift, shift); print "Processing type 3 total of $type3 and a type 4 total of $ty +pe4\n"; return; } __DATA__ 3 200 4 50 3 100 3 100 3 100 4 50 4 25

Gives:

C:\test>196448 3 - 200 4 - 50 3 - 100 Processing type 3 total of 200 and a type 4 total of 50 3 - 100 3 - 100 4 - 50 4 - 25 Processing type 3 total of 300 and a type 4 total of 75

Well It's better than the Abottoire, but Yorkshire!

In reply to Re: stoping and restarting a loop by BrowserUk
in thread stoping and restarting a loop by mnlight

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.