From: Piers Cawley Date: 2001-08-12T16:55:26+09:00 Subject: [ruby-talk:19583] Re: Setting $_ for the current scope Renald Buter writes: > On Thu, Aug 09, 2001 at 01:41:00PM +0100, ruby-talk@ruby-lang.org wrote: > > >>>>> "R" == Renald Buter writes: > > > > R> Of course I could always assign to $_, but would this assignment be > > R> local to the current scope? > > > > What do you call current scope ? > > > > $_ is a local, and thread local, variable. > > > > > > Guy Decoux > > By local I meant block-local, e.g. > > for ($bla) { > # $_ == $bla > for ($foo) { > # $_ == $foo > } > # $_ == $bla, again > } Nope, it's not block local. for ('bla') { my $f = 'wibble' tell; for ('foo') { $f = 'wobble' tell; } tell; } sub tell { print "\$_ is $_, "; print '$f is ', defined($f) ? $f : 'undefined'; print "\n"; } outputs $_ is bla, $f is undefined $_ is foo, $f is undefined $_ is bla, $f is undefined -- Piers Cawley www.iterative-software.com