On 10/20/06, Pit Capitain <pit / capitain.de> wrote:
> Paul van Delst schrieb:
> > (...)
> >
> >     if line =~ componentRegexp
> >       # We have matched an array component definition
> >       arrayList<<{"type"=>$1,
> >                   "param"=>$2,
> >                   "dimlist"=>$3.split(/\s*,\s*/), # <--- split dimlist
> >                   "name"=>$4,
> >                   "description"=>$5}
> >
> > but I've found that the above operation on the $3 captured result
> > appears to "wipe" the subsequent entries $4 (name) and $5 (description).
>
> Paul, the problem is that #split with a Regexp internally executes some
> Regexp matches which change $1, $2 etc. You have to capture the results
> of the first match before executing the split.

In this case, it's really easy: just reorder the lines so that the one
containing split will be the last (hash changes the order anyway):

       arrayList<<{"type"=>$1,
                   "param"=>$2,
                   "name"=>$4,
                   "description"=>$5,
                   "dimlist"=>$3.split(/\s*,\s*/)}

This will work fine as in the moment split messes  up those $x, you
don't need them any more. Obviously this would not work if there were
more splits.