in reply to Perl test management

Good idea. Well done. But you don't really need the extra last-number file. You can determine it on-the-fly. Hope the following code helps: The script will first look for sample_<number>.pl files, extract the biggest number, and start the next file with filename of sample_<last number + 1>.pl.

#!/usr/bin/perl -w use strict; use IO::Dir; my $rootdir = "."; my $lastno = GetLastNumber($rootdir) + 1; my $newpl = "$rootdir/sample_${lastno}.pl"; # forgot to add .pl extens +ion # thanks jweed. system "vim $newpl && rm current_test && ln -s $newpl current_test"; sub GetLastNumber { my $dir = shift; my $d = IO::Dir->new($dir) or die "Can not open directory $dir for read!"; my $lastno = 0; while (defined(my $f = $d->read)) { next if $f !~ /sample\_\d+\.pl/; my ($no) = $f =~ /sample_(\d+)\.pl/; $lastno = $no if $no > $lastno; } return $lastno; }

Replies are listed 'Best First'.
Re: Re: Perl test management
by jweed (Chaplain) on Nov 11, 2003 at 05:11 UTC
    Excellent. ++. I had this idea but was unsure as to implementation.

    P.S. There is a slight code bug. You test in GetLastNumber for a file of the format "sample_<number>.pl", but you create a file of the for "sample_<number>".

    Brain fart issue, I suppose. :)


    Who is Kayser Söze?