How to link only the maximum file name with the directory using perl?

perl

(Find Data) #1

I have the directory tree, with sub-directories & files in it?
I am using the query below to link the largest file name to a given directory.

This is my current code:

my $location = $output_dir;
open LOGFILE, $location;
my $first_line = 1;
my $max_id;
while (<LOGFILE>) {
    if (/rev_(\d)+/) {
        if ($first_line) {
            $first_line = 0;
            $max_id = $1;
        } else {
            $max_id = $1 if ($1 > $max_id);
        }
    }
}
close LOGFILE;

This is the directory tree:

.
`-- Muska
    |-- Muska.html
    |-- Muska_.config
    |-- Muska_.html
    `-- Muska_Digital
        |-- Digital_Verification
        |   |-- Digital_Verification.html
        |   |-- Muska_Muska_Digital_Digital_Verification_.config
        |   |-- Muska_Muska_Digital_Digital_Verification_.html
        |   `-- rev1
        |   |    |-- rev1.config
            |    |-- rev2.config
            |
             `-- rev2
        |       |-- rev1.config
        |       |-- rev2.config         
        `-- Muska_Muska_Digital_.html

This is The Expected Output:

.
`-- Muska
    |-- Muska.html
    |-- Muska_.config
    |-- Muska_.html
    `-- Muska_Digital
        |-- Digital_Verification
        |   |-- Digital_Verification.html
        |   |-- Muska_Muska_Digital_Digital_Verification_.config
        |   |-- Muska_Muska_Digital_Digital_Verification_.html
        |   `-- rev1
            |    |-- rev2.config
            |
             `-- rev2
       |       |-- rev2.config         
        `-- Muska_Muska_Digital_.html