lestrrat hits the nail on the head (and several posters came very close), but it bears expanding.

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:

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];
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];

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.