From: Martin DeMello Date: 2002-12-01T00:59:08+09:00 Subject: Re: Scope of regex match $variables Paul Melis wrote: > "Martin DeMello" wrote in message > news:Qd3G9.10876$Qr.203053@news3.calgary.shaw.ca... >> returns "ell" and nil. Is there any way to make the value of $1 persist >> when the function returns? > > From the Pickaxe book: > > "$1 to $9 - String - The contents of successive groups matched in the last > successful pattern match. In "cat" =~/(c|a)(t|z)/, $1 will be set to ``a'' > and $2 to ``t''. This variable is local to the current scope." Oops - should have read the Pickaxe more carefully before asking on the group. Thanks for the quick reply. > Looks like you have to save them explicitly yourself. Yeah, but I can't figure out a way to make them local to the calling scope, the way an actual Regexp#match call would. martin