Perl-Sensitive Sunglasses | |
PerlMonks |
Question: Capturing a repeated patternby robmderrick (Initiate) |
on Apr 08, 2010 at 21:32 UTC ( [id://833636]=perlquestion: print w/replies, xml ) | Need Help?? |
robmderrick has asked for the wisdom of the Perl Monks concerning the following question:
I think I need the big space of this over chatterbox to properly frame this 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:
... 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
Back to
Seekers of Perl Wisdom
|
|