Hallo Davide,
> Can someone convert this *very complex* C source to Perl :
> ------------------------------------------------------------
> #include <stdio.h>
> #include <stdlib.h>
> int main(int argc, char * argv[]) {
> unsigned t, i, n, tot, c;
> if (argc < 4) {
> printf("use: %s init_delay delay_incr num_retries\n", argv[0]);
> return 1;
> }
> t = atoi(argv[1]);
> i = atoi(argv[2]);
> n = atoi(argv[3]);
> tot = 0;
> for (c = 1; c <= n; c++) {
> printf("%02u\tsend-time = %-6u\tnext-try = %u\n", c, tot, t);
> tot += t;
> t += t / i;
> }
> return 0;
> }
> ------------------------------------------------------------
#!/bin/perl -w
use strict;
use vars qw($t $i $n $tot);
if (!defined($ARGV[2]))
{
printf "use: %s init_delay delay_incr num_retries\n", $0;
exit;
}
$t = $ARGV[0];
$i = $ARGV[1];
$n = $ARGV[2];
$tot = 0;
for (my $c = 1; $c <= $n; $c++) {
printf("%02u\tsend-time = %-6u\tnext-try = %u\n", $c, $tot, $t);
$tot += $t;
$t += ($t / $i);
}
Examples:
$ ./xmailresend.pl 1 2
use: ./xmailresend.pl init_delay delay_incr num_retries
$ ./xmailresend.pl 1 2 10
01 send-time = 0 next-try = 1
02 send-time = 1 next-try = 1
03 send-time = 2 next-try = 2
04 send-time = 4 next-try = 3
05 send-time = 8 next-try = 5
06 send-time = 13 next-try = 7
07 send-time = 20 next-try = 11
08 send-time = 32 next-try = 17
09 send-time = 49 next-try = 25
10 send-time = 74 next-try = 38
Gerrit
--
=^..^=
-
To unsubscribe from this list: send the line "unsubscribe xmail" in
the body of a message to [EMAIL PROTECTED]
For general help: send the line "help" in the body of a message to
[EMAIL PROTECTED]