The problem, I feel, is complex but perhaps you guys are more practiced in dealing with computers so it might be easier.
The difficult part of this is trying to make sense to you guys
I have lines of data elements in a .vim file (this can vary between 5 data elements per line and 25)
Each element is distinct from the others, regarded as a different sample
I have been reading one line of data and comparing it with the previous x number of lines of data, looking for matches in value
(which I have code for and can provide below)
I now have to be more specific, in that I have to read the individual data from each line, and eliminating any replication, keep adding new values until I have x amount of values.
so for example:
my input data would look something like this
1 2 6 4 5
6 7 8 9 10
1 2 11 12 13
6 14 15 16 17
If I chose to read 13 elements of data, i would read
1 2 6 4 5 6 7 8 9 10 1 2 11
Now I need to remove duplicate values, in this case one of the 1, one of the 2, and one of the 11 (but values could be triplicated or more)
so that would result in
1 2 4 5 6 7 8 9 10 11
This final line would then be compared with the next complete unread line in the file, with matches printed to one file and nonmatches printed to another as per the code below.
(so the match file would read)
6
(and the nonmatch file would read)
14 15 16 17
Now there is actually another step to what I do on paper that I would like the PERL script to perform
Initially I had chosen 13 values (and this can vary between 5 and upto 80)
If it is the case that duplicates are removed, I dont have the 13 values that I originally planned for
so on paper, I continue to read forward until I have my required number of values filled in (without duplicates)
even if that means reading into more lines of data, and moving forward the line that I will eventually compare with
Does this make any sense at all ? :)
thankyou
my $line = 4;
while (@lines > 3) {
# check first 3 lines against the 4th line
my @vals = split /\s+/, $lines[3];
my @chk = split /\s+/, join(' ', @lines[0..2]);
my %match;
foreach my $val (@vals) {
$match{$val}++ if grep { $val eq $_ } @chk;
}
my @match = sort keys %match;
my @nomatch = grep { not exists $match{$_} } @vals;
my $match = @match;
my $nomatch = @nomatch;
# do whatever you want with the matches and no-matches
print MATCH "$line: \tmatch = @match\n";
print NOMATCH "$line: \tnomatch = @nomatch\n";
$line++;
# get rid of first line so next loop will be 2-6 and so on
shift @lines;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.