M
Martin Foster
Hi.
I would like to be able to mimic the unix tool 'uniq' within a Perl script.
I have a file with entries that look like this
4 10 21 37 58 83 111 145 184 226
4 12 24 42 64 92 124 162 204 252
4 11 23 44 67 95 134 168 215 271
..
..
..
Many number sequences, I would like to analyze the file to tell me how often a
sequence occurs throughout the file.
I've began writing a script:
#!/usr/bin/perl
# Perl script to find most common CS
use strict;
my @line;
my $infile = "/home/martin/DATABASE/large.txt";
open INFILE, $infile or die "Shit! Couldn't open file $infile: $!\n";
my @array = <INFILE>;
my $no_lines = $#array;
print "There are ", $no_lines+1, " lines in the large array\n";
my (@table);
foreach my $array (@array) {
push(@table, [split(/\s/, $array) ]);
}
my $no_cells = $#{$table[$no_lines]};
for (my $k =0; $k<=$no_lines; $k++) {
print "[$k] occurs ";
my $match=0;
my $matched=0;
for (my $h =0; $h<=$no_lines; $h++) {
for (my $j =3; $j<=12; $j++ ) {
if ($table[$k][$j] == $table[$h][$j]){
$match++;
}
}
if ($match==10) {
$matched++;
}
}
print "$matched times\n";
} # end of large loop
Does anyone know a better, quicker method of doing this?
Many thanks in advance for any suggestions.
I would like to be able to mimic the unix tool 'uniq' within a Perl script.
I have a file with entries that look like this
4 10 21 37 58 83 111 145 184 226
4 12 24 42 64 92 124 162 204 252
4 11 23 44 67 95 134 168 215 271
..
..
..
Many number sequences, I would like to analyze the file to tell me how often a
sequence occurs throughout the file.
I've began writing a script:
#!/usr/bin/perl
# Perl script to find most common CS
use strict;
my @line;
my $infile = "/home/martin/DATABASE/large.txt";
open INFILE, $infile or die "Shit! Couldn't open file $infile: $!\n";
my @array = <INFILE>;
my $no_lines = $#array;
print "There are ", $no_lines+1, " lines in the large array\n";
my (@table);
foreach my $array (@array) {
push(@table, [split(/\s/, $array) ]);
}
my $no_cells = $#{$table[$no_lines]};
for (my $k =0; $k<=$no_lines; $k++) {
print "[$k] occurs ";
my $match=0;
my $matched=0;
for (my $h =0; $h<=$no_lines; $h++) {
for (my $j =3; $j<=12; $j++ ) {
if ($table[$k][$j] == $table[$h][$j]){
$match++;
}
}
if ($match==10) {
$matched++;
}
}
print "$matched times\n";
} # end of large loop
Does anyone know a better, quicker method of doing this?
Many thanks in advance for any suggestions.