in reply to Re: order of arguments evaluated
in thread order of arguments evaluated

That could be better written as
print join ',', @boxes;
unless you're concerned about the joined string being enormous, in which case I'd probably say
my $printed = 0; foreach my $box ( @boxes ) { print ',' if $printed++; print $box; }
But your code is perfectly safe. The alternatives are only evaluated if the corresponding condition indicates that they should be.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: order of arguments evaluated
by monarch (Priest) on May 31, 2005 at 23:28 UTC
    Indeed both are good suggestions, but the context was putting together HTML tables, hence a simple join wasn't satisfactory.

    The second solution was also good, but I was concerned about integer wrap-around, which could potentially evaluate to zero in the case of a HUGE table (being the paranoid programmer that I am, even though the likelihood of generating a 4,294,967,296 row table was unlikely).

    Hence the dodgy trinary operator statement.

      My second solution, like yours, will only increment the variable if it is zero, because logical-or is a short-circuiting operation.

      Before you get done generating a multi-billion-row table, I think you're going to have problems with browser timeout. :-)


      Caution: Contents may have been coded under pressure.