in reply to Finding un-paired files in a directory
You want the "*.did" files that have no corresponding ".mrg" file, right?
Hmmm... let me type something in here...
It doesn't handle the case of a lone ".mrg" file. To fix that...
:)
-Dave
Hmmm... let me type something in here...
This code takes advantage of the fact that you will have only one or two files with the same basename (and that there are only two extensions of interest). So, just count them up.use strict; use File::Find; my %temp; find( sub { s/mrg$/did/; /did$/ and $temp{$_}++; }, '.' ); my @files = grep { $temp{$_} == 1 } keys %temp; print "@files";
It doesn't handle the case of a lone ".mrg" file. To fix that...
The beauty of these code snippets (actually, they are working scripts) is that they don't do any filetests. File::Find (or readdir if you prefer) have already established the existence of the files -- checking for that again just slows down your code.use strict; use File::Find; my %temp; find( sub { m/^(.+)\.(mrg|did)/ and push(@{$temp{"$1.did"}}, $2) }, '.' ); my @files = grep { @{ $temp{$_} } == 1 and $temp{$_}->[0] eq 'did' } sort keys %temp; print "@files";
:)
-Dave
|
---|
In Section
Seekers of Perl Wisdom