in reply to Can't / won't print pipe delimiter?
I would just have used map to make that a lot more simple:
print map { "$_|" } @my_list
And a design pattern that you should start to recognize is that as soon as you see the concatenation operator, you should be thinking about changing that to a list. So
should change to$my_id_list .= $my_list[$i]."|";
Later, after you're done with the loop, you can join all of the list elements together.push ( @my_id, "$my_list[$i]|" );
And if your code also removes the last "|" from the strong that you're building, then you can do
during the loop andpush ( @my_id, $my_list[$i] );
at the end of the loop to get the same result.join('|',@my_id);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't / won't print pipe delimiter?
by punch_card_don (Curate) on May 18, 2009 at 18:39 UTC | |
by talexb (Chancellor) on May 18, 2009 at 21:04 UTC |