robmderrick has asked for the wisdom of the Perl Monks concerning the following question:
I have an input line that looks like:
somename 1000 0.24 280 2 2576.9 2731.9 12.0 4195.3
I am looking for a way to capture all nine elements with one pattern that allows me to use one subpattern to capture the the last 8 elements.
I.e, I tried this:
(@array) = $_ =~ /(^[a-z]\w*)/\s+([\.\d]+)/\s+([\.\d]+)/\s+([\.\d]+)/\s+([\.\d]+)/\s+([\.\d]+)/\s+([\.\d]+)/\s+([\.\d]+)/\s+([\.\d]+)\s*$/i
... but that is ungainly.
I lose a lot of it with the following:
my $p = qr/\s+([\.\d]+)/; (@array) = $_ =~ /(^[a-z]\w*)$p$p$p$p$p$p$p$p$/io;
... but I would sure like to know if there is a way to use that one pattern 8 times, like repeating a digit match 8 times with \d{8}
Does such an arcane method exist?
-- rob derrick