I have this code which reads a data file and compares values between lines of that data
it reads from the top of the file to the bottom. How do I change this to read from the bottom of the file (last entry) to the top (first entry) ?
while (@lines > 12) {
# check first 7 lines against the 8th line
my @vals = split /\s+/, $lines[12];
my @chk = split /\s+/, join(' ', @lines[0..11]);
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;
#my $vals = @vals;
#my $lines = @lines;
#print NUMBER "$lines @lines \n\n";
if ($match == 0) {
$zero ++
}
if ($match == 1) {
$one ++
}
if ($match == 2) {
$two ++
}
if ($match == 3) {
$three ++
}
if ($match == 4) {
$four ++
}
if ($match == 5) {
$five ++
}
if ($match == 6) {
$six ++
}
# 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.