I would instinctively use a regex with captures for this. In most cases, I would reserve split() for when I had many (or an arbitrary number of) similarly-delimited fields. Intuitive regex solution:
my ($number, $tail) = ($line =~ /^(\d{4}) (.*)/) or die "no match";bobf's suggestion of using unpack() would be more efficient, but it doesn't validate as it goes: it would split "ABCDEFGHIJK" into "ABCD" and "FGHIJK" without batting a proverbial eyelid. It's good if you trust your data, but it'd be premature optimisation to use it over a regex otherwise, IMO.
use subs map{uc,lc}"a".."z";AUTOLOAD{map{print/j|p/ ?uc:lc}${(caller!1)[3]}=~/.$/g;v32}(S.t)->(U\j),n(A ),(e,l~R)->(p!r->(E&O|H~t)),(E,r,q)((.))->(k\H,a^c)
In reply to Re: can split() use a regex?
by Irrelevant
in thread can split() use a regex?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |