from Perl to tcl - important

Discussion in 'Programming' started by oncy, May 24, 2008.

  1. #1
    Hello buddies!

    I have a perl script and it should be converted to tcl for my network test. This situation is very urgent and the scrip is just 32 lines. Thank you for your help :)

    #SCRIPT

    # explanation: perl throughput.pl <trace file> <granlarity>

    $infile=$ARGV[0];

    $granularity=$ARGV[1];

    $sum=0;

    $sum_total=0;

    $clock=0;

    $init=0;

    open (DATA,"<$infile")

    || die "Can't open $infile $!";



    while (<DATA>) {

    @x = split(' ');

    if($init==0){

    $start=$x[1];

    $init=1;
    }


    if ($x[1]-$clock <= $granularity)
    {

    $sum=$sum+$x[2];

    $sum_total=$sum_total+$x[2];
    }

    else

    {
    $throughput=$sum*8.0/$granularity;

    print STDOUT "$x[1]: $throughput bps\n";

    $clock=$clock+$granularity;

    $sum=$sum+$x[1];

    $sum=0;
    }

    }

    $endtime=$x[1];

    $throughput=$sum*8.0/$granularity;

    print STDOUT "$x[1]: $throughput bps\n";

    $clock=$clock+$granularity;

    $sum=0;

    #print STDOUT "$sum_total $start $endtime\n";

    $avgrate=$sum_total*8.0/($endtime-$start);

    print STDOUT "Average rate: $avgrate bps\n";

    close DATA;

    exit(0);
     
    oncy, May 24, 2008 IP