On 18/02/17 06:09, ToddAndMargo wrote: > On 02/17/2017 07:44 PM, yary wrote: >> Oh, then chain join on the end: >> >> my $StringReversedLines = >> $StringFullOfLineFeeds.lines.reverse.join("\n") >> >> or >> >> my $StringReversedLines = >> $StringFullOfLineFeeds.split("\n",:v).reverse.join >> **//___^ > > > Hmmm. I wanted to recreate the array, not reverse the line. > > > Well, when you have a string that contains newline characters you can use .lines to get an array with strings in it where each of the strings is the stuff from one newline character to the next.
You can then call .join("\n") on that array to get back to one long string with newline characters in between the original elements. When you use the :v argument to split, it will also give you a string in between that contains only the newline character in it (this is especially useful when you use a regex as the splitter, or an array of strings where each of the strings is one thing to split by). In that case you don't need to join with "\n", because the \n are already there. I think the examples were confusing your original question where you said "reverse of .lines", but you meant "inverse of .lines". So you can just leave out the .reverse from these examples. Hope that helps! - Timo