How to take the maximum digits file linked with the folder using perl?
my $location = $output_dir;
print $location;
open LOGFILE, $location;
my $first_line = 1;
#print $first_line;
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);
print $max_id;
}
}
}
close LOGFILE;
Obtained output:
|-- USB_FS
| |-- Database
| | |-- rev1
| | | |-- slater_ams_USB_FS_Database_rev1_.config
| | | `-- slater_ams_USB_FS_Database_rev1_.html
| | |-- rev2
| | | |-- slater_ams_USB_FS_Database_rev2_.config
| | | `-- slater_ams_USB_FS_Database_rev2_.html
| | |-- rev3
| | | |-- slater_ams_USB_FS_Database_rev3_.config
| | | `-- slater_ams_USB_FS_Database_rev3_.html
| | |-- slater_ams_USB_FS_Database_.config
| | `-- slater_ams_USB_FS_Database_.html
Expected output:
|-- USB_FS
| |-- Database
| | |-- rev3
| | | |-- slater_ams_USB_FS_Database_rev3_.config
| | | `-- slater_ams_USB_FS_Database_rev3_.html
| | |-- slater_ams_USB_FS_Database_.config
| | `-- slater_ams_USB_FS_Database_.html