in reply to Problem localizing $_ using threads::shared

Yes, you've just discovered the fact local $_ is broken in lots of interesting ways, mostly associated with internal magic. I've been doing some fixes in that area recently, so if you feel like reporting it using perlbug, I might get round to having a proper look at it sometime (there are already some existing local/shared bugs on my list to sort out at some point).

Dave.

  • Comment on Re: Problem localizing $_ using threads::shared

Replies are listed 'Best First'.
Re^2: Problem localizing $_ using threads::shared
by duelafn (Parson) on Nov 13, 2005 at 13:21 UTC

    Ah. Upon further study, there's nothing special about $_, it seems that any global or package variable that is bound to the original variable causes this.

    ## This code block causes problems use vars qw/ $g /; # or, "our $g;" sub doit_local { local $g = shift; $g =~ s/'/'\''/g; return $g; } sub get_md5sums { my $x = shift; print Dumper [$x, $$x{path}]; for $g ('find', $$x{path}, qw/-type f -exec md5sum {} ;/) { $$x{foo} .= '"'.doit_local($g).'"'; } return 1; }

    However, it is not a problem if we make a copy first

    ## This code block works as expected use vars qw/ $g /; # or, "our $g;" sub doit_local { local $g = shift; $g =~ s/'/'\''/g; return $g; } sub get_md5sums { my $x = shift; print Dumper [$x, $$x{path}]; for ('find', $$x{path}, qw/-type f -exec md5sum {} ;/) { $g = $_; $$x{foo} .= '"'.doit_local($g).'"'; } return 1; }

    I will write up some tests and report this using perlbug. Thanks a lot!

    Good Day,
        Dean