Hi:

I made the change and the env-yyyymmdd-0 file is indeed the first in the loop. Now they are not incrementing:
The next file should be env-yyyymmdd-1 env-yyyymmdd-2 etc, but instead I'm getting this:

checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
checking: env-20010712-0 for message, GDPN9D00.SRY
...

from this code snip..
<snip>

sub retrieve
{
my $num = shift;
$num =~ s/(\d\d)$//;
(my $minor = $1) =~ s/^0//;
return "env-$num-$minor";
}

sub normalize
{
my $file = shift;
my $s = sprintf("%02d",$1);
$file =~ s/^env-//;
$file =~ s/-(\d+)/$s/;
return $file;
}

opendir(CONTROL, $control_dir) or die "Can't open $control_dir: $!\n";
while (@controlfiles = grep(! /^\.\.?$/, readdir(CONTROL)))
{
#my @sorted_controlfiles = sort( { $a <=> $b } @controlfiles);
my @sorted_controlfiles = map retrieve($_),
sort map normalize($_), @controlfiles;
foreach my $ctrlfile ( @sorted_controlfiles )
{
print "checking: $ctrlfile for message, $msgfile\n";
}
}
close(CONTROL);

</snip>

I must be missing something.

gS


On Wednesday, July 18, 2001, at 06:17 PM, Jeff 'japhy/Marillion' Pinyan wrote:

On Jul 18, Groove Salad said:

Thanks for the quick response. I think what you've described is a bit
over my head. But, I'll try it and see what happens.

The files will always be, env-yyyymmdd-nn and will get rotated at months
end. However, your solution much more flexible.

Since they'll always be two digits, you can simplify my code a bit:

sub normalize {
my $file = shift;
$file =~ s/^env-//;
$file =~ s/-(\d+)/sprintf "%02d", $1/;
return $file;
}

sub retrieve {
my $num = shift;
$num =~ s/(\d\d)$//;
(my $minor = $1) =~ s/^0//;
return "env-$num-$minor";
}

In retrospect, my regex needn't have been so complex. We wanted to remove
the leading 0's, but not ALL of them -- only one or two, but not three.

s/^0{1,2}//;
# or
s/^00?//;

That said, my regex is now far simpler.

--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **


:bF
---

GIF image

Reply via email to