in reply to Re: What's broken in Perl 5?
in thread What's broken in Perl 5?

Can you characterize your bug a little more specifically? File::Find works perfectly for me with respect to symlinks, whether they point somewhere or not. In fact, I often use File::Find to locate dangling symlinks:
use File::Finder; # my wrapper around File::Find @nowhere = File::Finder->eval(sub { -l and not -e })->in($ENV{HOME});
So, what is your brokenness?

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^3: What's broken in Perl 5?
by fraterm (Scribe) on May 05, 2005 at 03:35 UTC

    Apologies for the delay, had to fetch File::Finder as it's not in the core perl and I wanted to have both methods detailed in the script.

    Here's a testcase:

    #!/usr/bin/perl # pragmata use warnings; use strict; use integer; # Modules use File::Finder; # merlyns wrapper around File::Find use File::Find; # core module # Prototypes sub wanted; sub dangling_symlink_handler; sub goFinder($); sub goFind($); # my $pathname = shift; chomp ($pathname); print "Querying Perhaps Broken Symlink Handling For $pathname \n"; # # generic find should grab anything and get anything that is valid print "call goFinder:\n"; goFinder($pathname); print "done goFinder:\n"; print "call goFind:\n"; goFind($pathname); print "done goFind:\n"; ################################################################### sub goFinder($){ my $searchpath = shift (@_); my @goodlinks = (); my @badlinks = (); print "in goFinder($searchpath)\n"; # Slightly modified merlynish example @goodlinks = File::Finder->eval(sub { -l and -e })->in($search +path); foreach (@goodlinks) { print "File::Finder Found good link:$_"."\n"; } @badlinks = File::Finder->eval(sub { -l and not -e })->in($sea +rchpath); foreach (@badlinks) { print "File::Finder Found bad link:$_"."\n"; } print "exiting goFinder($searchpath)\n"; } sub goFind($) { my $searchpath = shift (@_); print "in getFileList($searchpath)\n"; find( { wanted => \&wanted, no_chdir => 1, dangling_symlinks = +> \&dangling_symlink_handler }, $searchpath); print "exiting getFileList($searchpath)\n"; } sub wanted { print "\tWanted Sees This:\n\t".$File::Find::name."\n"; } sub dangling_symlink_handler { print "\tDangling Symlink Handler Sees This:\n\t".$File::Find: +:name."\n"; }

    So there it is, the stock File::Find find function doesn't call the dangling_symlink_handler as advertised (or as I read it's advertisment) and your File::Finder module finds stuff just fine, either it works around this behavior properly or I'm misunderstanding its behavior. As File::Finder is not a core module, I hadn't used it up 'til now thus avoiding convincing my superiors to allowing its installation.

    Squibbie Pooh Ski Doo.
      Ah, so that isn't a problem so much with File::Find in general, but with the recently-bolted-on dangling-symlink-handler thingy, which I've never used.

      (Reading docs quickly...)

      Hmm. Since it's immediately after the "follow" group of options, I bet it only kicks in when follow is enabled, which you haven't. However, I would then argue that it's a bit of a doc bug. Try rerunning your test with follow set to 1.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        I'll try that out. I don't recall it working then... I'd attempted to use the recently bolted on thing for awhile. It'd be odd if I didn't flail around to flip that switch in my throes of frustration... ;)
        UPDATE:I saw no change in behavior when modifying the follow parameter. I also twiddled chdir to no avail. and tried just setting dangling_symlinks to 1 to bomb out with an error if it ran across one. It didn't. Finder continues to find stuff...
        Squibbie Pooh Ski Doo.
Re^3: What's broken in Perl 5?
by fraterm (Scribe) on May 05, 2005 at 01:30 UTC

    I'll put together a demonstration case of the failure, but with both the AIX and Gentoo Linux version of perl the dangling symlink handler never gets called for me.

    This is with perl versions 5.8.5 on Linux and 5.8.0 on AIX 5.

    Squibbie Pooh Ski Doo.