How can I convert a scalar containing a string with newlines in an array with those lines as elements?
For example, considering this:
$lines = "line 1\nline 2\nline 3\n";
I want to retrieve this:
$lines[0] --> "line 1\n"
$lines[1] --> "line 2\n"
$lines[2] --> "line 3\n"
Ideally, I’d like to keep the newline in the aray elements.
Use
split:EDIT: to keep the newlines, split on
/^/mas mentioned in the comments, or use a zero-width look-behind, as mentioned in another answer.