On Apr 15, 2004, at 8:31 AM, Sten Berg wrote:

Sorry!
This is what I´ve come up with so far:

my $nr=0;
my @missing;
open (FILE, "<logfile.txt") or die "Can't open $file: $!\n";
print "Started\n\n";
while (<FILE>) {
 ($firstbit, $value)=split /:/,$_;
 $value=trim ($value);
 if ($firstbit eq "- value ") {
    if ($nr==256) {
        $nr=0;
        print "New Sequence Started\n";
    }
   if ("$value" ne "$nr") {
    print"read $value expected $nr\n";
     push (@missing,"$nr-$value\n");
     $nr = $value;
    }
    $nr++;
 }
}
print "missing ranges\n\n";
print for (@missing);
close FILE;
sub trim {
   my @out= @_;
   for (@out) {
       s/^\s+//;
       s/\s+$//;
   }
   return wantarray ? @out : $out[0];
}

What's wrong with the above code? It ran for me and said 3 - 255 was missing. What was it supposed to say?


What about something like:

#!/usr/bin/perl

use strict;
use warnings;

my $count = 0;
while (<DATA>) {
        if (m/^- value : (\d+)/) {
                unless ($1 == $count) {
                        if ($1 < $count) {
                                print "$_\n" foreach ($count..255, 0..($1 - 1));
                        }
                        else { print "$_\n" foreach $count..($1 - 1); }
                }
                $count = $1 >= 255 ? 0 : $1 + 1;
        }
}
print "$_\n" foreach $count..255;

__DATA__
- value : 0
some data...
- value : 1
some data...
- value : 2
some data...
- value : 255
some data...
- value : 0
some data...
- value : 1
some data...
__END__

It would be nice though, to be able to give the log filename as a parameter to the perlscript. If the filename differs from time to time, it would be nice if I could avoid having the filename within the script.

For that, change my


while (<DATA>) {

line to

while (<>) {

and call with

perl script_name file_name(s)

Hope that helps.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to