in reply to Re^3: Printing files that has two different extensions in a given directory
in thread Printing all the files that have both ".rtf" and ".ftp" by searching recursively in a given directory

Without repeating the extension:
use strict; use warnings; use File::Find::Rule qw( ); my %files; for ( File::Find::Rule ->file() ->name('*.rtf', '*.ftp') ->in('.') ) { my ($name) = /^(.*)\./; ++$files_by_ext{$name}; } say for grep {$files{$_} == 2} keys %files;
  • Comment on Re^4: Printing files that has two different extensions in a given directory
  • Download Code

Replies are listed 'Best First'.
Re^5: Printing files that has two different extensions in a given directory
by ikegami (Patriarch) on Apr 12, 2011 at 21:39 UTC

    I purposefully did not introduce the following errors from which your version suffers:

    • False positive when there are two .rtf and no .ftp with the same name.
    • False positive when there are no .rtf and two .ftp with the same name.
    • False negative when there are more than one .rtf and one .ftp with the same name.
    • False negative when there are one .rtf and more than one .ftp with the same name.
    • False negative when there are more than one .rtf and more than one .ftp with the same name.

    Don't know if it matters to the OP or not.

      Wait, you have a file system that allows two different files with the same name in a given directory?

        I have a file system that allows two different files with the same name in a given directory tree

        The OP said "foo" should be returned for

        foo.rtf data\foo.ftp

        He didn't say it shouldn't return "foo" for

        foo.rtf data\foo.ftp atad\foo.ftp

        Can this situation happen? Dunno. I chose to support it, and I pointed out that yours doesn't.

        Actually, yours doesn't even work for the case the OP mentioned explicitly, even after one fixes the compilation error.