G'day rmarkman,
Welcome to the Monastery.
Update (strike): I looked up the error message and made an incorrect inference. I suspect I read "off the end of the string" as "off the end of the array". Anyway, regardless of the reason, what I wrote is wrong and is now stricken.
You're getting the error because you're attempting to assign a value to an element past the end of the array. If you search for "Modification of a read-only value attempted" in "perldiag -- Perl diagnostic messages" you'll get a lot of information about this. However, the opening sentence sums up yor problem:
"You tried, directly or indirectly, to change the value of a constant."
Your split statement, as written, only produces 6 elements: ('A' .. 'F'). You can print $#flds or scalar(@flds) to confirm this.
When you add a LIMIT of -1, you get 10 elements. This behaviour is documented in split: there's examples roughly in the middle of the page.
With the code as posted, both $flds[16] and $flds[8] are undefined. Attempting to assign undef doesn't cause an issue:
$ perl -we 'undef=undef' $
Attempting to assign 0 generates the error you're getting:
$ perl -we 'undef=0' Modification of a read-only value attempted at -e line 1. $
If you use split like this:
@flds = split(/(\t)/, $value);
You'll get 18 elements. That's also documented (at the end of the page).
— Ken
In reply to Re: split problem
by kcott
in thread split problem
by rmarkman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |