Nov 19, 2001, 7:57 AM
Post #2 of 3
That seems like strange behaviour, but it's quite easy to explain.
The first thing you need to know is that the first argument to split is treated as a regular expression. The dot in a regular expression means "any character". So you tell Perl to split the string "98.23" at any character. If you split the string at any character, you obviously end up with six empty fields. So you'd normally expect the splice function to return something like:
But, as the perldoc for splice says, the function deletes empty trailing fields before returning the list. Since all fields are empty, splice returns an empty list.
@array = ('', '', '', '', '', '');
To make a long story short, what you want to do is:
Hope this helps.
my @array = split /\./, $total;