<<I would make that
for my $loopiter ( 1..$loopmax )
and get rid of the two subtractions.>>
I LIKE IT!
While brewing tea, it occurred to me to speculate on how a mischievous person
would go about killing this script. The one thing that occurred to me is that
you could invoke the script with a nonsense value like CATEGORY=bubububu. That
would lead to an empty set of terms with inscrutable (to me) results. I tried
to
shortstop that issue with the following addition to the code:
while (<FH>) {
if ( $topic eq "REVIEW" ) { $termnum[ $ops++ ] = $_; }
elsif (/$topic/) { $termnum[ $ops++ ] = $_; }
else {die "NO SUCH CATEGORY";} #ADDED LINE
}
Does that look reasonable? Other attempts to send the script garbage would just
cause it to tell you your answer was wrong, I think.
John M Rathbun MD
________________________________
From: Jim Gibson <[email protected]>
To: Perl Beginners <[email protected]>
Sent: Mon, September 17, 2012 10:18:16 PM
Subject: Re: Proposed correction
On Sep 17, 2012, at 6:52 AM, Shlomi Fish wrote:
> Hi,
>
> I apologise for having sent that to Dr. Rathbun in private - that was not my
> intention but a misuse of software. Resending to the list.
>
> On Sun, 16 Sep 2012 19:31:01 -0700 (PDT)
> [email protected] wrote:
>
>> for (my $loopiter = 0; $loopiter < $loopmax; $loopiter++) { #1
>> if ($loopiter >= ($loopmax - 1)) { die "Loop number
>> $loopnum has iterated $loopiter times" }
>
> This line (#2) will throw an exception in the final iteration of the loop,
> so it's not good.
I think you missed the part where the loop is supposed to terminate before
$loopiter becomes equal to $loopmax, and if it does not terminate before then,
it is an error.
> You can use:
>
> for my $loopiter (0 .. $loopmax-1)
> {
> }
I would make that
for my $loopiter ( 1..$loopmax )
and get rid of the two subtractions.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/