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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |