Dear Monks, I'm on need of wisdom,
The problem is that I'm having problems trying to use regexes to retrieve matches that are defined as one/none or more. I'm trying with a simple file as example:
1 23 456 789 0123 456 2 24 456 789 0123 456 3 23 456 789 0123 456 4 23 456 789 0123 456 5 23 456 789 0123 456
And I was wondering if it's possible to parse and assign them to variables in just one step. The regex I was trying to use was something like
while (<$fd>) { my $regex = '^(?:(\d+)\s+)+(\d+)$'; (my ($d1, $d2, $d3, $d4, $d5, $d6) = $_) =~ m/$regex/; print "Line $.\n"; print "\t$d1\n"; }
It doesn't work as I'd expect. It matches, but only retrieves the last two elements because instead of getting an array of results for the (?: )+ regex part it stores only the last one.
I know a split would work without that much of a hassle but.. shouldn't be possible to do that just with a regex? I've tried different things without success and I haven't found any relevant example of this.
Thanks,
In reply to Variable matching on a regex by LaintalAy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |