As others have said, your split command is ambiguous. It can take zero to three arguments. How many are you passing? What you really want is a list slice.
Because split creates a list, and because Perl makes a big deal out of context, you can apply list operations to the result of a split -- as you rightly expected. The trick is to disambiguate what you want.
A list slice is like an array slice, where you specify only the precise elements you want from the list. For example:
So you were on the right track. You only missed one little thing that occasionally trips me up -- telling Perl to treat the results of split as a list: $item = (split(/:/, $_))[1];my @numbers = (1, 2, 3, 4, 5); # want the first and third elements # first element is at position 0 my ($first, $third) = @numbers[0, 2];
Again, don't forget that the first element has an index of 0.
In reply to Re: Questions about split
by chromatic
in thread Questions about split
by blax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |