#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Fcntl qw(:flock); # import LOCK_* and SEEK_END constants $| = 1; my @value; my @value_2; my $i = 0; sub first { foreach my $argnum (0 .. $#ARGV) { open (READ, "<" , $ARGV[$argnum]) or die ("Could not open: ".$ARGV[$argnum]." - $!\n"); flock(READ, LOCK_EX) or die "Could not lock '".$ARGV[$argnum]."' - $!\n"; if (-z "".$ARGV[$argnum]."") { print READ "is empty!\n"; # -z File has zero size (is empty). } print "This is the \$ARGV[$argnum]: ".$ARGV[$argnum]."\n"; while ( my @doc_read = ) { chomp @doc_read; foreach $_ (@doc_read) { my @result = split (':', $_); if (/^\s*$/) { # /^\s*$/ check for "blank" lines may contain spaces or tabs next; } push (@{ $value[$i++] }, $result[3]); } $i = 0 if eof; } close (READ) or die ("Could not close: ".$ARGV[$argnum]." - $!\n"); } return @value; } sub second { foreach my $arg (@_) { open (READ, "<" , $arg) or die ("Could not open: ".$arg." - $!\n"); flock(READ, LOCK_EX) or die "Could not lock '".$arg."' - $!\n"; if (-z "".$arg."") { print READ "is empty!\n"; # -z File has zero size (is empty). } print "This is the \$arg: ".$arg."\n"; while ( my @doc_read = ) { chomp @doc_read; foreach $_ (@doc_read) { my @result = split (':', $_); if (/^\s*$/) { # /^\s*$/ check for "blank" lines may contain spaces or tabs next; } push (@{ $value_2[$i++] }, $result[3]); } $i = 0 if eof; } close (READ) or die ("Could not close: ".$arg." - $!\n"); } return @value_2; } my @result = &first(); my @result_2 = &second(@ARGV); print "\nValues \@result\n"; print "@$_\n" for @result; print "\nValues \@result_2\n"; print "@$_\n" for @result_2; #### Line_1:Line_1_1:Line_1_2:Line_1_3:Line_1_4 Line_2:Line_2_1:Line_2_2:Line_2_3:Line_2_4 #### Line_3:Line_3_1:Line_3_2:Line_3_3:Line_3_4 #### Line_4:Line_4_1:Line_4_2:Line_4_3:Line_4_4 Line_5:Line_5_1:Line_5_2:Line_6_3:Line_5_4 Line_6:Line_6_1:Line_6_2:Line_6_3:Line_6_4 Line_7:Line_7_1:Line_7_2:Line_7_3:Line_7_4 #### Values @result Line_1_3 Line_3_3 Line_4_3 Line_2_3 Line_5_3 Line_6_3 Line_7_3 Values @result_2 Line_1_3 Line_3_3 Line_4_3 Line_2_3 Line_5_3 Line_6_3 Line_7_3 #### push (@value , $result[3]); push (@array, [@value]); # Important to empty the array for the next file! @array = (); #### #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Benchmark qw(:all); # For timming reasons use Fcntl qw(:flock); # import LOCK_* and SEEK_END constants $| = 1; my @value_2; my @array_2; sub second { foreach my $arg (@_) { open (READ, "<" , $arg) or die ("Could not open: ".$arg." - $!\n"); flock(READ, LOCK_EX) or die "Could not lock '".$arg."' - $!\n"; if (-z "".$arg."") { print READ "is empty!\n"; # -z File has zero size (is empty). } while ( my @doc_read = ) { chomp @doc_read; foreach $_ (@doc_read) { my @result = split (':', $_); if (/^\s*$/) { # /^\s*$/ check for "blank" lines may contain spaces or tabs next; } push (@value_2 , $result[3]); } push (@array_2, [@value_2]); } @value_2 = (); close (READ) or die ("Could not close: ".$arg." - $!\n"); } return @array_2; } my @result_2 = &second(@ARGV); print Dumper(@result_2);