Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

•Re: Re: Finding un-paired files in a directory

by merlyn (Sage)
on Dec 02, 2003 at 12:16 UTC ( #311591=note: print w/replies, xml ) Need Help??

in reply to Re: Finding un-paired files in a directory
in thread Finding un-paired files in a directory

use strict; use Data::Dumper; chomp(my @files = <DATA>); # find unique basenames my @basenames = keys %{{ map { (split/\./)[0] => 1 } @files }}; # find unpaired files foreach my $basename (@basenames) { my @matches = grep (/$basename/, @files); print "$matches[0]\n" if $#matches == 0; }
No, this solution breaks if any filenames have regex-significant metachars, or are partially within a larger filename.

In my opinion, the original solution is actually the most direct, as this is a classic set difference problem.

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://311591]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2023-09-25 10:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found