#!/usr/bin/perl use strict; use warnings; package processLogFiles; sub new { my $class = shift; my $devices = { refArrayProcess => shift, refArrayConversion => shift, refArrayPrintOutputFile => shift, }; bless $devices, $class; return $devices; } sub processData { use Fcntl qw( :flock ); my ( $devices , @stdin ) = @_; my %file_hash = (); foreach my $file (@stdin) { open my $file_handle , '<' , $file or warn "unable to open file: ".$file." $!"; flock( $file_handle , LOCK_SH ) or die "Could not lock '".$file."' - $!\n"; my $log_file = (split(/\//,$file))[-1]; # Remove \n character and also blank lines chomp(my @lines = grep /\S/, <$file_handle>); # Push the data into a hash push(@{$file_hash{$log_file}}, @lines); close $file_handle or warn "unable to close file: ".$file." $!"; } return $devices->{refArrayProcess} = \%file_hash if (%file_hash); } sub arrayConversion { use Fcntl qw( :flock ); my ( $devices , @twoDimensionArray ) = @_; my @result; while ( @twoDimensionArray ) { my $next = shift @twoDimensionArray; if ( ref($next) eq 'ARRAY' ) { unshift @twoDimensionArray , @$next; } else { push @result, $next; } } return $devices->{refArrayConversion} = \@result if (@result); } sub processTimestampFile { use Data::Dumper; my ( $devices , @log_file ) = @_; print Dumper \@log_file; exit 0; my %info = %{ shift() }; my $data = "data.txt"; open my $write , '>>' , $data or die "Could not open file: ".$data." - $!\n"; flock( $write , LOCK_SH ) or die "Could not lock '".$data."' - $!\n"; my %data_hash = (); foreach my $data_file ( sort { @{$info{$b}} <=> @{$info{$a}} } keys %info ) { #print "$data_file: ", join(", ", sort @{ $info{$data_file} }), "\n"; $data_hash{$info{$data_file}[0]} = $info{$data_file}[3]; printf $write "%s %s\n" , $info{$data_file}[0] , $info{$data_file}[3]; } close $write or die "Could not close '".$data."' - $!\n"; #return $devices->{refArrayPrintOutputFile} = \%data_hash if (%data_hash); } 1;