I like the idea of processing the data (file) line-by-line, but I would parse the data records to a structure, an array of arrays of lines in which each top-level array element is a "chunk." Once you have the data parsed into a structure, you can do what you want with it.

Win8 Strawberry 5.8.9.5 (32) Fri 04/02/2021 20:38:05 C:\@Work\Perl\monks >perl use strict; use warnings; use autodie; use Data::Dump qw(dd); my $test_data = <<'EOD'; GO:0002366 False GO:0002446 True GO:0002275 True GO:0043312 True GO:0006733 False GO:0019674 False GO:0043588 False GO:0055065 False GO:0055080 True EOD use constant { 'TRUE' => 'True', 'FALSE' => 'False', }; my $rx_tf = qr{ \Q${ \TRUE }\E | \Q${ \FALSE }\E }xms; print "\$rx_tf $rx_tf \n"; # for debug open my $fh, '<', \$test_data; my @chunks; my $i_chunk = -1; while (my $record = <$fh>) { chomp $record; my $got_tf_rec = # true if record is valid my ($tf) = # extracted true/false field $record =~ m{ \A GO: \d{7} \s+ ($rx_tf) \Z }xms; die "bad t/f record: '$record'" if not $got_tf_rec; die "first t/f record not false: '$record'" if @chunks == 0 && $tf ne FALSE; ++$i_chunk if $tf eq FALSE; push @{ $chunks[ $i_chunk ] }, $record; } dd \@chunks; close $fh; exit; ^Z $rx_tf (?msx-i: True | False ) [ [ "GO:0002366 False", "GO:0002446 True", "GO:0002275 True", "GO:0043312 True", ], ["GO:0006733 False"], ["GO:0019674 False"], ["GO:0043588 False"], ["GO:0055065 False", "GO:0055080 True"], ]


Give a man a fish:  <%-{-{-{-<


In reply to Re: Parsing block of texts by AnomalousMonk
in thread Parsing block of texts by perlance

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.