Tanalis has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to grab information out of a series of files and place each file's data into an array of arrays for use later. Each file has a different number of pieces of information that I need to grab.
I'd like to do this using a foreach loop, iterating through each file, grabbing the data and assigning it to the array of arrays. I've defined an array of regular expressions, one for each file, that successfully grabs the data, however each regexp has a different number of strings to return.
What I'm wondering is how I can determine the number of returns ($1 .. $N) from a regexp, and return them, at run-time. Is there a variable somewhere that stores the number of matches, or do I need to store this myself (not a problem), and if so, is it legal to use code like
foreach ( 1 .. $numMatches ) { print $$numMatches }
to return each match?
Any comments or suggestions would be a great help.
-- Foxcub
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Returning N values from a Regexp
by thpfft (Chaplain) on Nov 13, 2002 at 13:15 UTC | |
|
(z) Re: Returning N values from a Regexp
by zigdon (Deacon) on Nov 13, 2002 at 13:18 UTC | |
by broquaint (Abbot) on Nov 13, 2002 at 13:41 UTC | |
|
Re: Returning N values from a Regexp
by diotalevi (Canon) on Nov 13, 2002 at 14:17 UTC | |
|
Re: Returning N values from a Regexp
by robartes (Priest) on Nov 13, 2002 at 13:02 UTC |