Re: [perl #38965] File::Find documentation - is "Don't modify thesevariables" still...
authorDavid Landgren <david@landgren.net>
Mon, 24 Apr 2006 13:02:02 +0000 (15:02 +0200)
committerSteve Peters <steve@fisharerojo.org>
Mon, 24 Apr 2006 15:27:39 +0000 (15:27 +0000)
Message-ID: <444CB02A.2000604@landgren.net>

p4raw-id: //depot/perl@27953

lib/File/Find.pm

index 497051e..9c81c6a 100644 (file)
@@ -215,8 +215,6 @@ through a collection of variables.
 
 =back
 
-Don't modify these variables.
-
 For example, when examining the file F</some/path/foo.ext> you will have:
 
     $File::Find::dir  = /some/path/
@@ -239,6 +237,18 @@ table below summarizes all variants:
               /etc               /                 /etc
               /etc/x             /etc              /etc/x
 
+Do not modify these variables. If you want to use C<$_>, it must
+be restored to its initial value before returning from the
+function. C<local> may be used for this purpose:
+
+  sub callback {
+    open my $fh, '<', $_ or die "Cannot open $_ for input: $!\n";
+    local $_; # localize $_ for the remainder of the routine
+    while (<$fh>) {
+      # manipulate $_
+    }
+    # $_ will be restored upon leaving
+  }
 
 When <follow> or <follow_fast> are in effect, there is
 also a C<$File::Find::fullname>.  The function may set