CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [GAR] Find last-backup file within a directory using Perl: Edit Log



FishMonger
Veteran / Moderator

Sep 20, 2012, 11:40 AM


Views: 2705
Re: [GAR] Find last-backup file within a directory using Perl


Code
#!/usr/bin/perl 

use strict;
use warnings;


my @files = qw(
Windows_Server_A_20120901
Windows_Server_A_20120902
Windows_Server_A_20120903
Windows_Server_B_20120901
Windows_Server_B_20120902
Windows_Server_B_20120903
Windows_Server_XZ_20120903
Windows_Server_XZ_20120901
Windows_Server_XZ_20120902
Windows_Server_XZ_20120903
);

my %newest;

foreach my $file ( @files ) {
no warnings qw(uninitialized);
my ($name, $date) = $file =~ /^(.+)_(\d+)/;
$newest{$name} = $date if $date > $newest{$name};
}

while (my ($name, $date) = each %newest) {
print "${name}_$date\n";
}



(This post was edited by FishMonger on Sep 20, 2012, 11:42 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Sep 20, 2012, 11:40 AM
Post edited by FishMonger (Veteran) on Sep 20, 2012, 11:41 AM
Post edited by FishMonger (Veteran) on Sep 20, 2012, 11:42 AM
Post edited by FishMonger (Veteran) on Sep 20, 2012, 11:42 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives