Sorry, in the first instance, for appearing to attribute error to you. The problem I intended to address, IMO, is threefold -- unwise use of a C-style loop, incorrect understanding of the /pattern/ in split and processing that doesn't touch the relevant data.
- You're absolutely correct to say "glenn's code...made no use of the counter aside from indexing." In fact, that pretty much encapsulates my first and third points -- sorry that wasn't clearer -- which is that iterating over an array but printing only the counter, $x, as in your code or glenn's won't get you the contents of the array. They're being extracted (NB exception below) and discarded to the bit bucket. If one merely wishes to create an ordered numeric sequence, there are better ways, one of which may, depending on circumstances, be the method you show.
- As to that 'exception' comment, glenn's @arr appears by magic, without a source, in the split line. If the source is a record andan array, as in OP's example, 1,1999,"ln with \n newline", and is somehow contained in the default var, $_ ... well, then the var isn't an array. Oops!
- And if the record is seen as a string, the cited code won't work because the pattern in split, "/\|/, is the token upon which the source data is separated. Perhaps the writer confused split and join. (Many replies seem to assume there are vbars in OP's data. I don't see them.)
Apologies to all those electrons which were inconvenienced by the creation of this post.