in reply to Question: Capturing a repeated pattern
#!/usr/bin/perl use strict; use warnings; $_ = 'somename 1000 0.24 280 2 2576.9 2731.9 12.0 4195.3'; my $regex = '(^[a-z]\w*)' . '\s+([\.\d]+)' x 8 . '$'; my (@array) = /$regex/io; print join "\n", @array; __END__ somename 1000 0.24 280 2 2576.9 2731.9 12.0 4195.3
Note as well that if you are operating on the special variable $_ there is no need to bind it to the regular expression.
You can also construct that in the regular expression itself using A bit of magic: executing Perl code in a regular expression, as described in perlretut.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question: Capturing a repeated pattern
by robmderrick (Initiate) on Apr 08, 2010 at 23:03 UTC |