#!usr/bin/perl
use strict;So far, so good
#use warnings;
Why did you comment that out?
The warnings pragma is used to help point out problems.
open FILE,"$ARGV[0]";
You should always check the return code of an open call and take proper action if it fails.
open FILE, $ARGV[0] or die "can't open $ARGV[0] $!";or use the 3 arg form of open and a lexical var for the filehandle.
open my $FILE, '<', $ARGV[0] or die "can't open $ARGV[0] $!";
my @file_array = <FILE>;
close(FILE);
Slurrping the data into an array is very rarely the best/proper approach.
my $i=0;
my @array;
my @scull;
foreach(@file_array) {
if($file_array[$i] =~ /=== Memops on thread 0 ===/)
{
for(my $j=0;$j<128;$j++)
{
So, you're iterating 128 times for every line in the file!
That is the most inefficient approach to proccess the array.
@array = split(" ", $file_array[$i+2+$j]);
@scull = $array[1]."\t".$array[4];
@scull will have a single element, so either use a scalar or use push to add it to the array.
$array[4] is the fifth field, but in your sample data, you only have 2 fields.What does your actual data look like and exactly what are you needing to compare?
#print "\n",@scull;
program(@scull);
program() is not a built-in Perl function, so did you create a subroutine, and if so, what does it do?
}
}
$i++;
}
As a short example, here's one way to find duplicate lines.
#!/usr/bin/perluse strict;
use warnings;
use Data::Dumper;
my %hash;
while ( <DATA> ) {
chomp;
$hash{$_}++;
}
print Dumper \%hash;
__DATA__
ld2 bd8290
ld3 33c1f54
ld2 bd8290
st2 33c1f54
st2 33c1f54
st4 bd8290
Here's what it will output.
$VAR1 = {
'ld2 bd8290' => 2,
'ld3 33c1f54' => 1,
'st2 33c1f54' => 2,
'st4 bd8290' => 1
};