So assuming I write
for my $loopiter (0 .. $loopmax) { #1
             if ($loopiter >= ($loopmax - 1)) { die "Loop number $loopnum has 
iterated $loopiter times" }
             $termnum[0] = int( rand($defnum) );
             last unless ( $termnum[0] == $lastnum );
             }
            $loopnum++;
and bearing in mind that these loops are only expected to run a few times, the 
plan is to generate an exception if one runs a ridiculous number of times, such 
as 1000, killing the script and notifying me by e-mail ala these earlier lines:
use Mail::Sendmail;
use CGI::carp qw(set_die_handler);
    BEGIN {
    sub handle_errors {
    my $msg = shift;
    sendmail(
    From    => 'i...@theinfosite.com',
    To      => 'jmrhide-theinfos...@yahoo.com',
    Subject => 'Tutorial Feedback',
    Message =>  $msg,
    );
    }
    set_die_handler(\&handle_errors);
    }
Plus I plan to put the sysops on notice when I start testing the thing so they 
can alert me if they see a problem like zombies popping up all over their 
server 
network.

Reasonable?

<<Why are you assigning and checking $termnum[0] (the 0th element of the 
array @termnum)? This seems wrong.>>

The array @termnum holds a list that points to several of the terms out of a 
much longer list that will be presented as possible answers in a multiple 
choice 
question. The objective of all these loops is to create lists that are 
randomized, non-duplicative, and don't contain the same term as was the focus 
of 
the previous question (which actually involved a prior iteration of the script, 
so this iteration has to recover that info from a cookie). This process gets 
fairly complex toward the end of the tutorial when the questions have five 
possible answers; the example I chose was the simplest. Hopefully if I modify 
all the loops similarly, we'll have the beast tamed!

Thanks for your helpful comments!

 John M Rathbun MD




________________________________
From: Shlomi Fish <shlo...@shlomifish.org>
To: jmrhide-p...@yahoo.com
Sent: Mon, September 17, 2012 3:01:19 AM
Subject: Re: Proposed correction

Hi,

On Sun, 16 Sep 2012 19:31:01 -0700 (PDT)
jmrhide-p...@yahoo.com 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 ogood.

>              $termnum[0] = int( rand($defnum) );
>              last unless ( $termnum[0] == $lastnum );

Why are you assigning and checking $termnum[0] (the 0th element of the 
array @termnum)? This seems wrong.

>              }
>             $loopnum++;
> 
> This may be ugly, but the first line adapts something in perlsyn:
> 
> for (my $i = 0; $i < @ary1; $i++) {Leaving aside other concerns, for
> the moment, is there a better way to write that first line?
> 

You can use:

for my $loopiter (0 .. $loopmax-1)
{
}

Regards,

    Shlomi Fish

>  John M Rathbun MD



-- 
-----------------------------------------------------------------
Shlomi Fish      http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

Chuck Norris was never a newbie! He will kill anyone who implies otherwise. In
a very not newbie-like manner.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Reply via email to