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

$my_id_list .= $my_list[$i]."|";
should change to
push ( @my_id, "$my_list[$i]|" );
Later, after you're done with the loop, you can join all of the list elements together.

And if your code also removes the last "|" from the strong that you're building, then you can do

push ( @my_id, $my_list[$i] );
during the loop and
join('|',@my_id);
at the end of the loop to get the same result.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

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
    Create an array, multiple pushes, then a join, instead of multiple appends and a regex - - - ya, it certainly codes cleaner.

    Aren't you supposed to be in the backyard barbecuing?

        Aren't you supposed to be in the backyard barbecuing?

      Just came back from a nice long bike ride. The steaks are defrosting on the counter. Red wine is open. Grill at 6pm, then .. hockey's on at 730pm. Happy May 24!!

      Alex / talexb / Toronto

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds