|Welcome to the Monastery|
Re: strange usage of s///by smls (Friar)
|on Sep 03, 2013 at 17:21 UTC||Need Help??|
This variation of yours does in fact work (prints "abc def"), and so do the following ones (which are closer to the original solution by "tails"):
Thus I conclude that the original "solution" is the result of a typo (separator '/' put in the wrong place), and cannot work.
As for how the corrected variations listed above work, lets break it down:
If the input string in $_ has an even number of characters (which seems to be implicitly assumed here), then this expression will return a string consisting of only dots, of half the length of the input string. E.g. for the input string "abcdef" it returns "...".
This is a common trick to execute a piece of code, and insert the code's return value directly into a string without introducing a temporary variable. It works because Perl interpolates anything that looks like an array variable inside a string.
All of them do the same thing: Insert a space after the third character of the original string, i.e. right in the middle.
why $" is different from literal space character in this regex?
It isn't, unless you've manually changed that variable.