develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #59750] File::Find behavior with files among @DIRS

Thread Next
James E Keenan via RT
January 12, 2012 17:24
[perl #59750] File::Find behavior with files among @DIRS
Message ID:
On Thu Oct 09 08:39:46 2008, wrote:
> The File::Find documentation never mentions any possibility of
> including non-directories among @DIRS, but it seems to be
> possible and the resulting behavior seems to be about what one
> would hope for: preprocess and postprocess don't get called,
> but wanted gets called with $File::Find::dir containing the
> directory name and $_ containing the bare file name. This is
> useful behavior (in the sense that if you wanted to write a
> script that could accept a mix of file and directory arguments,
> and File::Find /didn't/ do this, you'd have to write a fairly
> fiddly wrapper around File::Find to accomplish the same thing).
> So, unless there is a really strong objection to documenting the
> current behavior (or on some platforms it actually won't work),
> it would be nice to document it so people know it's available.
> There is one small point where the behavior for a non-directory
> in @DIRS differs from the normal behavior: $File::Find::dir
> winds up with a terminal / where normally it does not. Nothing
> the user can't work around with a File::Spec->canonpath, but
> it might be nice to make it consistent.

If I am reading the File::Find source code correctly, there is some
provision inside File::Find::_find_opt() for handling items passed to
the caller-level subroutines which are not, in fact, directories:

    462 sub _find_opt {
    463     my $wanted = shift;
    577     unless ($Is_Dir) {
    578         unless (($_,$dir) = File::Basename::fileparse($abs_dir)) {
    579         ($dir,$_) = ('./', $top_item);
    580         }
    620 }

(I haven't studied the code between lines 577 and 620 well enough to say
what's happening.)

But the OP is correct with regard to the silence of the documentation on
the handling of non-directories.  Do we need changes in the documentation?

Thank you very much.
Jim Keenan

via perlbug:  queue: perl5 status: new

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About