Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

by merlyn (Sage)
on Dec 02, 2003 at 12:13 UTC ( #311590=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

opendir DIR, $dir or die "Couldn't open directory '$dir' : $!"; my @files = grep { /(.*)\.mrg$/ and not -f "$1.did" } readdir DIR; closedir DIR
No, that's testing "-f" on a file in the current directory for a name that should be checked in a different directory. A traditional readdir mistake. {grin}

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

Replies are listed 'Best First'.
Re^3: Finding un-paired files in a directory
by Coruscate (Sexton) on Dec 02, 2003 at 21:26 UTC

    Which is why globing can be so lovely, as it includes the file path for you :) I'm not sure if this is any faster than Abigail-II's solution. At least this does only check for the existence of each file once rather than two checks.

    my $dir = '/path/to/dir'; print join ", ", grep { /(.*)\.mrg\z/ and not -f "$1.did" } <$dir/*\.mrg>'

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2023-10-04 02:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found