G'day tel2,
"... why mine wasn't working?"
I believe you're working on the erroneous assumption that split(/[, ]+/, <DATA>) will assign its result to $_. That assignment to $_ only occurs in a select number of cases. From "perlsyn: Compound Statements":
"If the condition expression of a while statement is based on any of a group of iterative expression types then it gets some magic treatment. The affected iterative expression types are readline, the <FILEHANDLE> input operator, ... If the condition expression is one of these expression types, then the value yielded by the iterative operator will be implicitly assigned to $_."
For each of your while iterations, the condition is true three times, once for each DATA line; however, $_ is not set for any of those iterations. On the fourth iteration, there are no more DATA lines and the loop ends.
Always add
use strict; use warnings;
to the top of your code. In this instance, although it wouldn't give a detailed explanation of the problem as I've provided, it would have hinted at a starting point for investigating the issue.
— Ken
In reply to Re^3: Splitting in while loop
by kcott
in thread Splitting in while loop
by tel2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |