From: Nicholas Clark Date: Fri, 27 Feb 2004 16:27:19 +0000 (+0000) Subject: Create a new local $_ without triggering tie by using local *_ = \my $a X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc125c03185ff3f765451ef53228eea11c0d525f;p=p5sagit%2Fp5-mst-13.2.git Create a new local $_ without triggering tie by using local *_ = \my $a (an idea from Ton Hospel, Message-Id: ) p4raw-id: //depot/perl@22401 --- diff --git a/lib/File/Find.pm b/lib/File/Find.pm index 5f590e2..49fa48a 100644 --- a/lib/File/Find.pm +++ b/lib/File/Find.pm @@ -592,7 +592,7 @@ sub _find_opt { $follow_skip, $full_check, $untaint, $untaint_skip, $untaint_pat, $pre_process, $post_process, $dangling_symlinks); local($dir, $name, $fullname, $prune); - for (my $_temp) { # creates a local $_ without retaining magic + local *_ = \my $a; my $cwd = $wanted->{bydepth} ? Cwd::fastcwd() : Cwd::getcwd(); my $cwd_untainted = $cwd; @@ -743,7 +743,6 @@ sub _find_opt { } } } - } } # API: diff --git a/lib/File/Find/t/find.t b/lib/File/Find/t/find.t index c55b4a9..8c312dd 100644 --- a/lib/File/Find/t/find.t +++ b/lib/File/Find/t/find.t @@ -15,8 +15,8 @@ BEGIN { $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; } } -if ( $symlink_exists ) { print "1..189\n"; } -else { print "1..79\n"; } +if ( $symlink_exists ) { print "1..195\n"; } +else { print "1..85\n"; } # Uncomment this to see where File::Find is chdir'ing to. Helpful for # debugging its little jaunts around the filesystem. @@ -497,6 +497,41 @@ Check( scalar(keys %Expect_Dir) == 0 ); Check( scalar( keys %pre ) == 0 ); } +# see thread starting +# http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2004-02/msg00351.html +{ + print "# checking that &_ and %_ are still accessible and that\n", + "# tie magic on \$_ is not triggered\n"; + + my $true_count; + my $sub = 0; + sub _ { + ++$sub; + } + my $tie_called = 0; + + package Foo; + sub STORE { + ++$tie_called; + } + sub FETCH {return 'N'}; + sub TIESCALAR {bless []}; + package main; + + Check( scalar( keys %_ ) == 0 ); + my @foo = 'n'; + tie $foo[0], "Foo"; + + File::Find::find( sub { $true_count++; $_{$_}++; &_; } , 'fa' ) for @foo; + untie $_; + + Check( $tie_called == 0); + Check( scalar( keys %_ ) == $true_count ); + Check( $sub == $true_count ); + Check( scalar( @foo ) == 1); + Check( $foo[0] eq 'N' ); +} + if ( $symlink_exists ) { print "# --- symbolic link tests --- \n"; $FastFileTests_OK= 1;