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.

In reply to Can't / won't print pipe delimiter? by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.