Re: Problem modifying captured regexp results

From: Paul van Delst [mailto:[email protected]]

So can someone elaborate on why the above split operation on
captured regexp results seems
to bugger up the other captured results? Does this issue
extend to any operation on
captured regexp results?

That’s what you get for using the (thread-local) global variables that
change with each regexp operation.

Regexp.match returns a MatchData object that will allow you to save your
results from a previous operation and not have them changed by later
code.

See the $~ variable,
http://phrogz.net/ProgrammingRuby/tut_stdtypes.html#objectorientedregula
rexpressions
and
http://phrogz.net/ProgrammingRuby/ref_c_matchdata.html

Gavin K. wrote:

Regexp.match returns a MatchData object that will allow you to save your
results from a previous operation and not have them changed by later
code.

Hello,

I agree with what you’re saying. I actually have already switched to
MatchData objects
rather than the $-variables – for all the usual reasons.

So, while my initial question may be less interesting now (since I have
working code), I’m
still curious why in the statement

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

operation on $3 modifies $4 and $5? (And, similarly, operation on $1
would “clear” $2 to $5)

Based on your first sentence, I guess I have an updated question:

Does using the split method on a $-variable count as a “regexp
operation”?

cheers,

paulv