I think the problem is that when you use shift, you're trying to alter its argument, which you can't alter (I haven't tried that particular maneuver, but I imagine it's the same error I get from pop=~s/foo/bar/). The solution is pretty simple, though: treat the split return as a list (I believe this is one of those cases where the difference between a list and an array matters), which you can index things out of, like so:
Note that if you want to use this as the first argument to a list operator (such as print), you need to do something to keep it from interpreting (split //, $string) as the arguments to the list operator (using the "if it looks like a function" rule), and complaining that you can't take an index out of print (can you tell I'm familiar with the error messages? ;-) :my $first = (split//,$string)[0];
print +(split//,$string)[4];
In reply to Re: How can I use the the return value of split without assigning?
by ChemBoy
in thread How can I use the the return value of split without assigning?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |