G'day pryrt,

That must be an extremely sharp, obsidian-bladed, cutting implement that you're using to split such a fine hair. I applaud your hairdressing skills.
💈 💇 👏

"I wouldn't have mentioned this, ..."

I've no problem with you mentioning special variables, especially the less commonly used ones. In my opinion, the more exposure they get the better.

"... but you went on to encourage the use of $" and interpolating the array in a string."

I would not say that offering an option that could be used in "rare situations" qualifies as encouraging such usage.

"If all you are doing is trying to get a separator ... then $, will work without having to interpolate/stringify."

Let's see how that pans out. The default for $" is ' ' so, except in "rare situations", there would be no need to localise a new value. The default for $, is undef so, in most situations, there is a need to localise a new value.

# A simple scenario printing a named array: $ perl -e 'my @x = qw{a bcd ef}; print "@x\n"' a bcd ef $ perl -e 'my @x = qw{a bcd ef}; { local $, = ","; print @x, "\n" }' a,bcd,ef, # Oops! Bogus comma at the end. Better split the print list. $ perl -e 'my @x = qw{a bcd ef}; { local $, = ","; print @x; print "\n +" }' a,bcd,ef # A more complex scenario printing an expression which evaluates to a +list: $ perl -e 'print "@{[f()]}\n"; sub f { qw{a bcd ef} }' a bcd ef $ perl -e '{ local $, = ","; print f(), "\n"; } sub f { qw{a bcd ef} } +' a,bcd,ef, # Oops! Bogus comma at the end. Better split the print list. $ perl -e '{ local $, = ","; print f(); print "\n"; } sub f { qw{a bcd + ef} }' a,bcd,ef

Notes:

Based on the results above, I will continue to put arrays in interpolating quotes when I print them. That not a recommendation; just what I'll be doing; everyone is free to make their own choices.

— Ken


In reply to Re: Splitting Hairs [tangent to: Splitting in while loop] by kcott
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.