Additional information to the information provided by @Mat:
In split "\.", ... first split parameter is first interpreted as a double-quoted string before passing it to the regex engine. As Mat said inside a line with two quotes, and \ is an escape character meaning "take the next character literally", for example. for things like double quotes inside a string with two quotes: "\""
So your split gets a "." like a template. A single dot means "division into any character." As you know, the split itself is not part of the results. Thus, as a result, there are several blank lines.
But why is the first element undefined instead of empty? The answer lies in the documentation for split : if you do not impose a limit on the number of elements returned by split (its third argument), then it will silently remove empty results from the end of the list. Since all elements are empty, the list is empty, so the first element does not exist and is undefined.
You can see the difference with this particular fragment:
my @p1 = split "\.", "thing"; my @p2 = split "\.", "thing", -1; print scalar(@p1), ' ', scalar(@p2), "\n";
It outputs 0 6 .
The βrightβ way to handle this, however, is what @ soulSurfer2010 said in a post.
source share