On Thu, 24 Oct 2002 22:39:06 -0700, [EMAIL PROTECTED] (John W. Krahn)
wrote:
>You don't really need the do/while loop in this case and you should
>include an error message if the rename fails. Also, you could limit the
>scope on the temporary variables.
>
>my $testfile = 'test.txt';
>
>{ my ( $file, $ext ) = $testfile;
>if ( -e $file ) {
> $file = sprintf 'test.%03d', ++$ext while -e $file;
> rename $testfile, $file or die "Cannot rename $testfile: $!";
> }
>}
>
>open my $fh, '>', $testfile or die "Cannot open $testfile: $!";
>
>
>
>John
>--
>use Perl;
>program
>fulfillment
It may be good to end on overflow condition too.
$file = sprintf 'test.%03d', ++$ext while -e $file && $ext < 1000;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]