in reply to Re^5: Splitting in while loop
in thread Splitting in while loop
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
²: 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splitting Hairs [tangent to: Splitting in while loop]
by kcott (Archbishop) on Oct 08, 2021 at 19:20 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 08, 2021 at 23:53 UTC | |
by kcott (Archbishop) on Oct 09, 2021 at 03:11 UTC | |
by LanX (Saint) on Oct 09, 2021 at 00:32 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 09, 2021 at 00:44 UTC | |
by LanX (Saint) on Oct 09, 2021 at 11:54 UTC | |
| |
|
Re: Splitting Hairs [tangent to: Splitting in while loop]
by LanX (Saint) on Oct 08, 2021 at 14:28 UTC |