Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Maybe it would help if you added a print just after the loop, to confirm you have exited the loop, as follows:

} if ( $x =~ m/^Patient/ ) { print "matched here"; last WID; } } print "out of loop"; if ( $obj->has_members ) { dump_members($obj); } }

I wonder what output dump_members($obj) is producing.

update3 I suspect you are calling your subroutine more than once. Each call produces one or two tagged (e.g. <DATE></DATE>) blocks of data. Your loop within the subroutine is probably exiting as you expect (note that if you put the last before your print statement the print doesn't execute) but the caller then calls again with more data and your subroutine produces more output. You can test for this by adding a print "starting dump_afp" at the start of your subroutine.

update: If you post a dump of the object you are passing to the subroutine I can try running it and let you know what happens on my system.

update2: Here is the result of running your sub through B::Deparse. I see nothing obviously wrong.

$ perl -MO=Deparse test.pl BEGIN { $^W = 1; } sub dump_afp { my $obj = shift @_; my $struct = $obj->struct; my(@keys) = sort(grep((!/^_|^(?:Data|EscapeSequence|ControlCode|Le +ngth|CC|(?:Sub)?Type|FlagByte)$/), keys %$struct)); push @keys, 'Data' if exists $$struct{'Data'}; WID: foreach my $key (@keys) { next if ref $$struct{$key}; next unless length($x = $$struct{$key}); 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 =~ /^"(\w|\d|\$)/) { $x =~ s/"|\(|\)//g; if ($x =~ m[^\d\d/\d\d/\d\d\s]) { my(@dateinfo) = split(/\s/, $x, 0); 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 (not $x =~ m[^\d\d/\d\d/\d\d] and $x != 'Patien +t') { if (not $x =~ /^((\d+)||(\d+,\d+))\.\d\d/) { print '<DESCRIPTION>'; print $x; print "</DESCRIPTION>\n"; } } } if ($x =~ /^((\d+)||(\d+,\d+))\.\d\d/) { print '<AMOUNT>'; print $x; print "</AMOUNT>\n"; } if ($x =~ /^((\$\d+)||(\$\d+,\d+))\.\d\d/) { print '<TOTAL>'; print $x; print "</TOTAL>\n"; } } } if ($x =~ /^Patient/) { last WID; } } if ($obj->has_members) { dump_members($obj); } } test.pl syntax OK

In reply to Re: Break perl foreach loop by ig
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found