logo       

Re: Perl Quiz-of-the-Week Suggestion: msg#00055

Subject: Re: Perl Quiz-of-the-Week Suggestion

Hi;

I've enjoyed reading the quizzes, although I confess I've been too busy to tackle any of them myself - given my hack level of perl expertise. I had to write a quick utility yesterday to compare the contents of two directories and come up with identically named files. What I came up with is listed below. It's quick and dirty, taking two directories names as input parameters and putting out a list of names. I thought you might like this as an example for your Quiz of the Week, because I know that there has to be a more elegant way to do this. I'd also like the report to have more info on the files - showing their file dates and sizes in each directory - which is what I'm working on.

If this turns out to be something handled completely by a module that already exists, sorry to have bothered you.

Thanks,
John



@temp = sort glob($dir1 . "*.*");
foreach (@temp) {
        if (-f $_) {
                s(^.*\\)();
                push(@dir1,$_);
        }
}
@temp = sort glob($dir2 . "*.*");
foreach (@temp) {
        if (-f $_) {
                s(^.*\\)();
                push(@dir2,$_);
        }
}
foreach $outerstr (@dir1) {
        foreach $innerstr (@dir2) {
                if ($outerstr =~ $innerstr) {
                        push(@dirboth,$outerstr);
                }
        }
}
if (@dirboth) {
        print("Found matching filenames. They will be stored in DIRBOTH.TXT\n");
        open(TMPWORK, "> DIRBOTH.TXT");
        printf TMPWORK ("Filenames found in both $dir1 and $dir2\n\n");
        foreach (@dirboth) { printf TMPWORK ("$_\n"); }
        close TMPWORK;
} else {
        print("No matching filenames found in $dir1 and $dir2\n");
}

**********************************************************************
This e-mail and any files transmitted with it are considered
confidential and are intended solely for the use of the
individual or entity to whom they are addressed (intended).
This communication is subject to agent/client privilege.
If you are not the intended recipient (received in error) or
the person responsible for delivering the e-mail to the
intended recipient, be advised that you have received this
e-mail in error and that any use, dissemination, forwarding,
printing or copying of this e-mail is strictly prohibited. If
you have received this e-mail in error please notify the
sender immediately.

**********************************************************************
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe