was the other solution that is not satisfactory. Why not?
Because, as you've found out, repeated captures don't work. (I've often wanted it myself.)
splitting a thousand fields into an array takes about 300 times longer than selecting 3 fields out of the line
Fair enough. One alternative is to repeat the capture manually. Something like:
@jam = $ham =~ m/\t([^\t]+)\t+([^\t]+)\t+([^\t]+)/;;
print @jam;;
spam spam yam
If the number required isn't known until runtime, you can generate the regex on the fly.
Another possibility is to capture the whole lot in a single capture and then split it:
( $jam ) = $ham =~ m/^[^\t]*\t[^\t]*((?:\t[^\t]*){3})\t[^\t]*$/;;
@jam = split /\t+/, $jam;;
print @jam;;
spam yam
A real example would get answers that address the real problem.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|