On Mon, Apr 12, 2010 at 05:00:49PM -0400, Eric Brine wrote: > On Sun, Apr 11, 2010 at 3:46 PM, Vincent Pit <perl@profvince.com> wrote: > > > > > > There are a couple of long-standing open tickets (from Michael Schwern) > > > to the effect that with tied arrays and hashes, > > > local @tied > > > doesn't DWIM (RT #7938, #7939). > > > > > > The current behaviour of local @tied is to create a new array, store it > > > in the ARRAY slot of *tied, and then I<attach tie magic to the new array > > > too>. This makes the local essentially a noop, and gives the following > > > behaviour: > > > > > > > > My preferences in descending order are 2,1,3. > > > > > > > Just a couple of notes to add to the discussion : > > - localized tied scalars remains tied. > > > > Which is quite annoying. > > sub func { > my ($fn) = @_; > local $_; > open(my $fh, '<', $fn) or die; > while (<$fh>) { > ... > } > } > > for ($foo, $bar) { > func($_); > } > > Do you see the bug in the above? Despite an attempt to privatize $_, the > while is loop is unknowingly calling magic some modules away because a > variable that's not even in the current function ($bar) happens to be tied. > > my $_; avoids the common case of this problem. with commits 5afa72af5aa99c40932771ad390abf5ba229611b 191ad7eff570fc96c93993e4358f83e2033365d6 these localisation actions now leave you with an untied thinggy: local @tied_array local %tied_hash local $tied_scalar -- A walk of a thousand miles begins with a single step... then continues for another 1,999,999 or so.Thread Previous | Thread Next