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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question: Capturing a repeated pattern
by kennethk (Abbot) on Apr 08, 2010 at 21:55 UTC | |
by robmderrick (Initiate) on Apr 08, 2010 at 23:03 UTC | |
|
Re: Question: Capturing a repeated pattern
by rubasov (Friar) on Apr 08, 2010 at 22:05 UTC | |
by robmderrick (Initiate) on Apr 08, 2010 at 22:19 UTC | |
by BrowserUk (Patriarch) on Apr 08, 2010 at 22:34 UTC | |
by rubasov (Friar) on Apr 08, 2010 at 22:43 UTC | |
by GrandFather (Saint) on Apr 08, 2010 at 23:41 UTC | |
by rubasov (Friar) on Apr 09, 2010 at 00:04 UTC | |
|
Re: Question: Capturing a repeated pattern
by LanX (Saint) on Apr 08, 2010 at 22:50 UTC |