Front page | perl.perl5.porters |
Postings from March 2000
Re: What's left to do? [LONG]
From:
scozens
Date:
March 22, 2000 20:10
Subject:
Re: What's left to do? [LONG]
Message ID:
492568AB.0014BC16.00@pwj-gw-n001.pwj.co.jp
> I cannot but wonder why there are *any* local()s left there.
> Does one intend to make use of dynamic scoping?
I'm ashamed to say I merely assumed they were there for a reason
and things would break with the recursion in subtle ways beyond
my comprehension if I took them away.
Looking at it again, this appears not to be the case:
(Where lib/File/Find.pm has the local's commented out:)
$ perl -Ilib -MFile::Find -e 'find(
sub {print "Dir:",$File::Find::dir,
"\nName:", $File::Find::name,"\n"},
q|/|)' > new
$ perl -MFile::Find -e 'find(
sub {print "Dir:",$File::Find::dir,
"\nName:", $File::Find::name,"\n"},
q|/|)' > old
$ diff old new
$
This makes life easier.
> I suggest simply having all examples always explicitly import what
> they want access to.
Good thinking. Why does the File::Find module export those two
functions without being asked to anyway? The documentation only
shows this by example, and doesn't state that they're exported.
However, since I have no desire to break every existing piece
of code that depends on this feature, it'll have to stay.
Ten or fifteen minutes, he said. Maybe for someone competent...
--- lib/File/Find.pm~ Thu Mar 23 11:18:18 2000
+++ lib/File/Find.pm Thu Mar 23 13:06:00 2000
@@ -11,17 +11,24 @@
=head1 SYNOPSIS
- use File::Find;
+ use File::Find qw(find);
find(\&wanted, '/foo', '/bar');
sub wanted { ... }
- use File::Find;
+ use File::Find qw(finddepth);
finddepth(\&wanted, '/foo', '/bar');
sub wanted { ... }
- use File::Find;
+ use File::Find qw(find);
find({ wanted => \&process, follow => 1 }, '.');
+ use File::Find qw(find $name)
+ find(\&wanted, '/foo', '/bar');
+ sub wanted {
+ open (FH, $name) or die "Couldn't open $name: $!";
+ ...
+ }
+
=head1 DESCRIPTION
The first argument to find() is either a hash reference describing the
@@ -119,7 +126,8 @@
the complete pathname to the file. You are chdir()'d to
C<$File::Find::dir> when
the function is called, unless C<no_chdir> was specified.
When <follow> or <follow_fast> are in effect there is also a
-C<$File::Find::fullname>.
+C<$File::Find::fullname>. These three variables may be imported into the
+caller's namespace.
The function may set C<$File::Find::prune> to prune the tree
unless C<bydepth> was specified.
Unless C<follow> or C<follow_fast> is specified, for compatibility
@@ -127,7 +135,11 @@
available: C<$File::Find::topdir>, C<$File::Find::topdev>,
C<$File::Find::topino>,
C<$File::Find::topmode> and C<$File::Find::topnlink>.
-This library is useful for the C<find2perl> tool, which when fed,
+If no import list is given, C<&find> and C<&finddepth> are imported
+by default. If you wish to import any of the variables C<$name>, C<$dir>
+and C<$fullname>, be sure to import the appropriate function as well.
+
+This module is useful for the C<find2perl> tool, which when fed,
find2perl / -name .nfs\* -mtime +7 \
-exec rm -f {} \; -o -fstype nfs -prune
@@ -174,6 +186,7 @@
@ISA = qw(Exporter);
@EXPORT = qw(find finddepth);
+@EXPORT_OK = qw($name $dir $fullname);
use strict;
@@ -399,8 +412,6 @@
my $dir_pref= ( $p_dir eq '/' ? '/' : "$p_dir/" );
my $dir_rel= '.'; # directory name relative to current directory
- local ($dir, $name, $prune, *DIR);
-
unless ($no_chdir or $p_dir eq '.') {
my $udir = $p_dir;
if ($untaint) {
@@ -558,8 +569,6 @@
my $dir_rel = '.'; # directory name relative to current
directory
my $byd_flag; # flag for pending stack entry if $bydepth
- local ($dir, $name, $fullname, $prune, *DIR);
-
unless ($no_chdir or $p_dir eq '.') {
my $udir = $dir_loc;
if ($untaint) {