If you just print an array (as in print @_) there will be nothing to show where each element starts and ends

Technically, there will be something: the value of the special variable $, -- it just happens that it defaults to undef (‡) so the separator used is nothing when printed. But if you change or localize its value to a different value, there will be a separator, without having to stringify the array first.

I wouldn't have mentioned this, but you went on to encourage the use of $" and interpolating the array in a string. If all you are doing is trying to get a separator for printing an array or other list (²), then $, will work without having to interpolate/stringify.

-- pryrt


‡: ... and apparently ignores use warnings 'uninitialized';: gotta love magic variables.

²: However, $, applies to everything when printing in list context, so local $,=',';print $a, @_, $b will have more separator instances than local $,=undef; local $"=','; print $a, "@_", $b; -- which may or may not be what you want.

³: Also, $, is much easier to use in a Windows cmd.exe one-liner than $". As a workaround, use English to the rescue:

C:\usr\local\share>perl -MEnglish -wle "@_ = qw{a bcd ef}; print qq(@_ +); local $LIST_SEPARATOR=','; print qq(@_)" a bcd ef a,bcd,ef

In reply to Splitting Hairs [tangent to: Splitting in while loop] by pryrt
in thread Splitting in while loop by tel2

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.