http://www.perlmonks.org?node_id=764667

punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Memographic Monks,

I have

@my_list = (3, 5, 2, 9); for $i (0 ..$#my_list) { print $my_list[$i]."|"; }
outputs
3529
If I change the print to
print $my_list[$i]."XX";
it outputs
3XX5XX2XX9XX
If I change it to
print $my_list[$i]."|n";
it outputs
3|n5|n2|n9|n
But it will not output
3|5|2|9|
as I want. Not even if I try
print $my_list[$i]."\|";

I know, pipe, perl control character....what's the trick to get it to print what I want?

Thanks.

UPDATE

Aie - holiday Monday programming - ok, time to take my lumps -

the code I provided was a short form for the real code which was

@my_list = (3, 5, 2, 9); for $i (0 ..$#my_list) { ... a bunch of stuff... $my_id_list .= $my_list[$i]."|"; ... a bunch more stuff... } print $my_id_list;
where more scanning the code revealed this helpful little line
#trim trailing delimiter $my_id_list =~ s/\|$//;
in ...a bunch more stuff..., which of course was the wrong place for it. Should'a been after the lop and before the print.

So, lessons #3,673,592 & #3,673,593: don't code half asleep on a holiday Monday; post real code or at least a sanitized version of it, not shortcuts.

Let the flagellation begin.




Time flies like an arrow. Fruit flies like a banana.