in reply to Splitting Hairs [tangent to: Splitting in while loop]
in thread Splitting in while loop

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

Replies are listed 'Best First'.
Re^2: Splitting Hairs [tangent to: Splitting in while loop]
by eyepopslikeamosquito (Archbishop) on Oct 08, 2021 at 23:53 UTC

      There are others (e.g. !! and 0+) which I use regularly but rarely recognise as secret operators and, even if I do, their names often allude me.

      In contrast, there's an infamous one which is impossible to unsee and, therefore, impossible to forget. I've not named it on purpose: in the hope that I may have saved at least some from mental trauma. :-)

      — Ken

      did anyone ever suggest just a mundane "code interpolation" ?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      Update: corrected s/profane/mundane/ (false friend)