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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.