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:

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


In reply to Question: Capturing a repeated pattern by robmderrick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.