CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
system command

 



robertodb
New User

Sep 27, 2011, 5:45 AM

Post #1 of 4 (355 views)
system command Can't Post

I have to repeat a NS2 simulation a number of times, each time changing the number of network nodes, and calculate an average. Tcl script creates a file named "winfile" after the execution. The perl script is

Code
$sum=0; 
$average=0;
$j=0;

for($i=2; $i<=10;$i++){

system ("ns tesina.tcl $i");

open (DATA,"<$winfile")
|| die "Can't open $winfile $!";


while (<DATA>) {
@x=split(' ');
$sum=$sum+$x[1];
$j++;

}
$average=$sum/$j;
print STDOUT "$i $average\n";
$sum=0;
$average=0;
$j=0;

}
close DATA;
exit(0);

but when I run it tells me can not open the file, despite being created from the execution of the tcl files. By modifying the file in this way

Code
$infile=argv[0]; 
...

it works. but I always get the same average value, which is impossible. It seems that the script does not run tcl but analyze a file previously created.
how can I fix that?


(This post was edited by robertodb on Sep 27, 2011, 5:49 AM)


rovf
Veteran

Sep 27, 2011, 7:50 AM

Post #2 of 4 (348 views)
Re: [robertodb] system command [In reply to] Can't Post

Is this really the *complete* program, which you have posted? If this is the case, proceed as follows:

(1) Please add

use strict;
use warnings FATAL => qw(all);

on top of your program and re-run it

(2) If it dies, post the complete error message


FishMonger
Veteran / Moderator

Sep 27, 2011, 7:57 AM

Post #3 of 4 (347 views)
Re: [robertodb] system command [In reply to] Can't Post

Check the return code of the system call to see if it was successful.

See: perldoc -f system


robertodb
New User

Sep 28, 2011, 2:49 AM

Post #4 of 4 (338 views)
Re: [FishMonger] system command [In reply to] Can't Post

ok guys...I've fixed it. I've changed the system statement in this way


Code
system ("./ns tesina.ns $i")


anyway thank you so much

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives