APM: some simple questions

Mike Stok mike at stok.co.uk
Tue Jan 27 12:51:22 CST 2004


On Tue, 27 Jan 2004, Wayne Walker wrote:

> On Tue, Jan 27, 2004 at 12:10:43PM -0600, Goldilox wrote:
> > is it better form to do this:
> > 
> > while($exlen > 0){$indent=$indent."  ";$exlen=$exlen-1;}
> > 
> > or this
> > 
> > while($exlen){$indent=$indent."  ";$exlen=$exlen-1;}
> > 
> > (or is the second one even going to work?)
> 
> Both should work (didn't test it, nor did I test this...)
> This should also work
> 
> $indent .= ("  " x $exlen);
> 
> see "perldoc perlop"  search for " x "  minus the quotes

Hmmm, if $exlen happens to start out with a value < 0 then the second 
while loop may take a while to complete.  Wayne's solution is safer (and 
you could even say something like this

  use constant INDENT_SPACES => 2;		# &nbsp; per space

  $indent .= '&nbsp;' x (INDENT_SPACES * $exlen);
 
if the mood took you...)

Mike

-- 
mike at stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike at exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA



More information about the Austin mailing list