As described in the docs for split, there's an optional 3rd arg, which says how many elements you want returned; "-1" returns all possible, even those that happen to be empty strings after the last non-empty element. (Default is to truncate the return list after the last non-empty element.) | [reply] |
Hi,
From split doc,
"Empty trailing fields, on the other hand, are produced when there is a match at the end of the string (and when LIMIT is given and is not 0), regardless of the length of the match".
use strict;
use warnings;
my $string = "/home/source::::::::DATE:SUBJECT:NAME::::::";
my @array = split(/:/,$string, -1);
$" = '><';
print "<@array>\n";
print scalar(@array);
output:
-------
</home/source><><><><><><><><DATE><SUBJECT><NAME><><><><><><>
17
| [reply] [d/l] |
From the perldoc documentation, if the LIMIT (3rd Argument) is unspecified or zero, trailing null fields are stripped off.
If you don't want that then pass the LIMIT as -1.
| [reply] |