Old monk here that couldn't even remember my original membername...
I have a foreach loop that I need to stop after a certain match is made. I added a Label to start the foreach loop, but when I match my condition and call Last, it does not end. Can another set of eyes help me see what I'm not seeing? This is a customized subroutine from afpdump.pl (parsing the details from a .afp file). After I read the total, I do not want to read any other dates or info. The match works perfectly but calling Last does not.
TIA
sub dump_afp { my $obj = shift; my $struct = $obj->struct; my @keys = sort grep !/^_|^(?:Data|EscapeSequence|ControlCode|Leng +th|CC|(?:Sub)?Type|FlagByte)$/, keys %$struct; push @keys, 'Data' if exists $struct->{Data}; WID: foreach my $key (@keys) { next if ref $struct->{$key}; length($x = $struct->{$key}) or next; if ($obj->ENCODING and grep { $key eq $_ } $obj->ENCODED_FIELDS) { $x = $obj->$key; $x = qq("$x"); } elsif ($x =~ /[^\w\s]/) { $x = ""; } if ($key eq 'Data') { if($x =~ m/^\"(\w|\d|\$)/) { $x =~ s/\"|\(|\)//g; if($x =~ m/^\d\d\/\d\d\/\d\d\s/){ my @dateinfo = split(/\s/, $x); if($dateinfo[0] =~ m/^\d\d\/\d\d\/\d\d/) { print "<DATE>"; print $dateinfo[0]; print "</DATE>\n"; print "<DESCRIPTION>"; print $dateinfo[1]; print "</DESCRIPTION>\n"; } } else { if($x =~ m/^\d\d\/\d\d\/\d\d/) { print "<DATE>"; print $x; print "</DATE>\n"; } if (($x !~/^\d\d\/\d\d\/\d\d/)&&($x != "Patient")){ if ($x !~ /^((\d+)||(\d+,\d+))\.\d\d/){ print "<DESCRIPTION>"; print $x; print "</DESCRIPTION>\n"; } } } if ($x =~ m/^((\d+)||(\d+,\d+))\.\d\d/){ print "<AMOUNT>"; print $x; print "</AMOUNT>\n"; } if($x =~ m/^((\$\d+)||(\$\d+,\d+))\.\d\d/) { print "<TOTAL>"; print $x; print "</TOTAL>\n"; } } } if ($x =~ m/^Patient/){ last WID; } } if ($obj->has_members) { dump_members($obj); } }

In reply to Break perl foreach loop by pvecchio

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.