[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] do... while? SPOILER



At 14:33 -0700 07/02/1999, Vicki Brown wrote:
>		my $bContinueLooking = 1;
>		do {
>		    if ( $#aListOfOldAceFiles == -1 ) {
>		      $bTransferTags = 0;
>		      $bContinueLooking = 0;
>		    }
>		    else {
>		      $szOldAceFile = shift @aListOfOldAceFiles;
>		      $bIsAnAceFile = &bCheckIfThisIsAnAceFile( $szOldAceFile );
>		      if ( $bIsAnAceFile ) {
>		        $bTransferTags = 1;
>		        $bContinueLooking = 0;
>		      }
>		    }
>		  } while( $bContinueLooking );

>You can tell from the prefixes where this code comes from :-)


At 18:18 -0500 07/02/1999, Tushar Samant wrote:
>I can't, actually.

I didn't mean you'd recognize the script, only that this hails from 
the same place as several other recent windowsish-c++ish examples 
I've posted. The code (I didn't write it) I'm working through this 
past week.

At 23:17 -0400 07/02/1999, tomr@aceldama.com wrote:
>I'll assume that your code duplicates the original extremely ugly
>code, at which I don't want to look. I'd probably shorten this to:

character for character, including two extra } } I mis-clipped :-(


I wouldn't have bothered with the LABEL meself.

First get rid of the do { } while. It's a useful little construct in 
its place but it's meant to be used when you need to force the loop 
to go through at least once regardless of the value of the condition. 
Since the condition was forced to be true before the loop, 
while($bContinueLooking) { ... } will suffice.

But... why set $bContinueLooking at all. The purpose of that variable 
is as a flag to decide whether to stay in the loop or leave; that can 
be done with last.

Also, as Tushar commented, why are we destroying the array? It turns 
out we don't need it later, but what's the point?

My solution would be

   $IsAnAceFile = 0;
   foreach(@ListOfOldAceFiles) {
       $IsAnAceFile = IsAnAceFile( $_ );
       last if ($IsAnAceFile)
   }
   $TransferTags = 0 unless ($IsAnAceFile);

It turns out (in context) that it is important to assign 
$TransferTags to 0 (unsetting the flag) if no appropriate file is 
found, rather than to set it to 1 if a file is found, but that wasn't 
obvious from the fragment.  That is, I failed to mention (it's 
difficult to know how much to put in) that this loop is inside the 
following if statement

if ( $bTransferTags ) {

  ...
  my $bContinueLooking = 1;
  do { ...
  }; ...
}

Points awarded to Tushar, Larry, Bernie and Tom and the folks who 
sent me comments offline. It's interesting (to me) to see how the 
results differ (TMTOWTDI) but are also very similar.

Was it fun? (I have fun rewriting this sort of stuff...)

-- --
        |\      _,,,---,,_       Vicki Brown <vlb@cfcl.com>
  ZZZzz /,`.-'`'    -.  ;-;;,_   Journeyman Sourceror: Scripts & Philtres
       |,4-  ) )-,_. ,\ (  `'-'  P.O. Box 1269  San Bruno  CA  94066
      '---''(_/--'  `-'\_) http://www.cfcl.com/~vlb  http://www.macperl.com

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org