#!c:\perl\bin\ use strict; #must find way to use deref in my statement use File::DosGlob 'glob'; use Class::Struct; use Getopt::Std; use vars qw($opt_a); getopts('a:'); my $logPath = "\\\\" . $opt_a . "\\d\$\\iims\\history"; print "Searching $logPath\n"; struct ( DEVICE => { datetime => '$', devicetype => '$', zip => '$', version => '$'}); my %Unique_DeviceType; my %Unique_SN; foreach my $logfile (glob("$logPath\\*")){ open (LOG, "<$logfile") or die "Can't open $logfile: $!"; while(){ chomp; #pull off newline s/^\s+//; #pull out leading whitespace s/\s+$//; #pull out trailing whitespace s/\s*,\s*/,/g; #pull out whitespace around commas s/\[|\]//g; #remove [ ] around date time stamp next unless length; #move to the next line unless there is something left in this one my @entry = split(/,/, $_); #split entry: Date Time DeviceType SN ZIP Version my @date = split(/:/, $entry[0]); #create datetime YYYYMMDDHHMMSS my @time = split(/:/, $entry[1]); my $datetime = $date[2] . $date[1] . $date[0] . $time[0] . $time[1] . $time[2]; $Unique_DeviceType{$entry[2]}++; #Add entry to unique list of Device Types if (!exists $Unique_SN{$entry[3]}) { #If this is first occurance $Unique_SN{$entry[3]} = new DEVICE; #Add entry to unique list of SNs $Unique_SN{$entry[3]}->datetime($datetime); $Unique_SN{$entry[3]}->devicetype($entry[2]); $Unique_SN{$entry[3]}->zip($entry[4]); $Unique_SN{$entry[3]}->version($entry[5]); } elsif ($datetime > $Unique_SN{$entry[3]}->datetime) { #If this occurance is newer $Unique_SN{$entry[3]}->datetime($datetime); $Unique_SN{$entry[3]}->zip($entry[4]); $Unique_SN{$entry[3]}->version($entry[5]); } } } foreach my $key (keys(%Unique_SN)){ print $key . "\n"; }