You want the "*.did" files that have no corresponding ".mrg" file, right?
Hmmm... let me type something in here...
use strict;
use File::Find;
my %temp;
find( sub { s/mrg$/did/;
/did$/ and $temp{$_}++; }, '.' );
my @files = grep { $temp{$_} == 1 } keys %temp;
print "@files";
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.
It doesn't handle the case of a lone ".mrg" file.
To fix that...
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";
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.
:)
-Dave
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|