Sorry, I should have been much more specific. The problem is to find a set of regex's that would mark blocks of text. So it doesn't matter how many are on a line, or where. Once one regex is matched, all lines following, up to and including the next match, are considered within the block of code. The lines within blocks are to be returned to standard output.

I have two working scripts, one that uses alternation, and one that uses a loop. The way my teacher is, it's usually apparent what he expects that doesn't make it into the spec, and it seems to me, he intends for there to be a loop. But, I don't see the problem with using just regex. Would it be slower than having a loop that searches one regex at a time and can stop once it finds one? Is that even a relevant question?

106 ^L[18:27:43 kelly@kudzu lab6]$ cat 4.pl 107 #! /usr/bin/perl 108 # 109 # CIS 33A Programming In Perl 110 # Lab #6.4 111 # Due Date: Monday, Nov 22 112 # Written By: Kelly Price 113 # 114 use strict; 115 use warnings; 116 117 die "Usage: $0 infile outfile regexs...\n" if @ARGV < 3; 118 open(FIN, "$ARGV[0]") or die "Error openning $ARGV[0] for readin +g: $!\n"; 119 open(FOUT, ">$ARGV[1]") or die "Error openning $ARGV[1] for writin +g: $!\n"; 120 121 my (@regexs) = splice(@ARGV, 2); 122 my $rexs = '(' . join('|', @regexs) . ')'; 123 124 my $inblock = 0; 125 print FOUT grep { 126 my $match = 0; 127 if (/$rexs/) 128 { 129 $inblock = $inblock ? 0 : 1; 130 $match = 1; 131 } 132 $inblock or $match; 133 } <FIN>; 134 135 [18:27:46 kelly@kudzu lab6]$ 4.pl 4.pl 4.out \\{ \\} 136 [18:28:00 kelly@kudzu lab6]$ cat 4.out 137 print FOUT grep { 138 my $match = 0; 139 if (/$rexs/) 140 { 141 } 142 $inblock or $match; 143 } <FIN>;

In reply to Re^2: Alternation vs. looping for multiple searches. by kprice++
in thread Alternation vs. looping for multiple searches. by kprice++

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.