#!/bin/env perl

# Usage example:    nextseq.pl dfile
#                               ^
#                               | file list of directories with names run_dd
#  exit code =  next number in sequence

use strict;
use IO::File;
use Env;

    my $logName = $ARGV[0];
    my $seq = 0;


    my $logh = new IO::File("< $logName");

    foreach my $linelog (<$logh>)
       {
       #   drwxr-sr-x    2 timb     lcddata      4096 May 14 20:52 run_01
       #   drwxr-sr-x    2 timb     lcddata      4096 May 14 20:52 run_02
	   if ($linelog =~ /d.+\s+\d+\s+.+\s+.+\s+\d+\s+\w+\s+\d+\s+.+\s+run_(\d\d)/)
	   {
	       $seq = $1;
	   }
       }



$seq += 1;
#print "seq = $seq", $/;

exit($seq);


