You don't know the last element ... but you know the first. Using that knowledge, you can enhance your logic as follows:
my $first = 0; # a flag to remember the first +element while(elements to check) { # * if (elem should be printed) { # * if ($first == 0) { $first = 1; } # don't print a comma before th +e first element else { print ","; } # print a comma print elem # * } }
HTH, Rata
Update: marked the pseudocode of the original poster with # * to reduce confusionIn reply to Re: printing lists...
by Ratazong
in thread printing lists...
by daverave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |