from Perl to C++ and tcl

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

  1. #1
    I have a program and it needed to be converted TO TCL(I prefer) or C++. I believe it is not a big deal to convert 30 lines script please help me it is urgent thank you for helping me. :)

    #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
  2. Aphex

    Aphex Guest

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    int main(int argc, char *argv[])
    {
    	infile = argv[0];
    	char *granualarity;
                 granualarity = argv[1];
    	int sum = 0;
    	int sum_total = 0;
    	int clock = 0;
    	int init = 0;
                 int start;
                 int endtime;
    
    	FILE *fp = fopen(infile,"rb");
    	if (fp == NULL) {
    		MessageBox(0,"Cant open file",0,0);
    		return 0;
    	}
    
    	while (fp) {
    		//need your own custom split function
    		x = split(" " );
    		if (init == 0) {
    			start = x[1];
    			init = 1;
    		}
    
    		if (x[1]-clock <= granualarity) {
    			sum += x[2];
    			sum_total += x[2];
    		} else {
    			throughout = sum * 8 / granualairty;
    			printf("x[1]: throughput bps\n",x[1]); //..
    			clock += granualairty;
    			sum += x[1];
    			sum = 0;
    		}
    	}
    
    	endtime = x[1];
    	throughput = sum * 8 / granualarity;
    	printf("x[1]: throughput,x[1]);
    	clock += granualarity;
    	sum = 0;
    
    	printf("sum_total: %x, start: %x, endtime: %x,sum_total,start,endtime);
    	avgrate = sum_total * 8 / endtime-start;
    	printf("Average rate: %x",avgrate);
    	fclose(fp);
    
    	return 0;
    }
    
    Code (markup):
    Not 100% correct. But, you get the point.
     
    Aphex, May 24, 2008 IP
  3. oncy

    oncy Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you. However, I need %100 correct one if it is possible because I have no background in programming and I should use it for network test and if it si possible tcl conversion could be better :)
     
    oncy, May 24, 2008 IP