Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system call and unwanted spaces. 1

Status
Not open for further replies.

kungphu

Programmer
Joined
May 23, 2006
Messages
13
Location
GB
Hi I have looked at this forum


I am trying to make a system call to a perl program from another perl program. The program which is being called takes two numbers as its parameters. The first of which is a number read in from a text file ie 1,2,3 etc and then the second number is a number which is less than or equal to the first number. I have a while loop that evaluates each line in the text file before moving onto the next one.

The call should look like this

perl prog.pl 2 1

but what i get is

Perl prog.pl 2
1
unknown comand 1
My code is as follows. I did try both single quotes and double quotes for the system call.
Code:
#!/usr/bin/perl5.8.5

use strict();

    open(FILE, "numbers.pid") or die ("unable to find file\n"); # opens the geturl 'pid file'
    @instancearray = <FILE>;                                            # stores the values into an array called
    close(FILE);	
    
    my $i =0; # accesses data in array 
    my $a = 1; # needed as secondary value for call to get url
    
    
    
    foreach $line (@instancearray)	
    {
	while ($a<=$instancearray[$i])
	{
	    # print "test\n";
	     
	    print "restarting instance number $instancearray[$i]$a \n";
	    system ("perl prog.pl $instancearray[$i] $a")==0;
	    $a = $a+1;
	}
	
	
	$i++;
	$a = 1;
    }			         
    
     open(OUT,"numbers.pid") or die ("unable to find output file\n");#
     $instancearray = ();
     foreach $number (@instancearray)#
     {#
 	print OUT "$number\n";#
     }#
 
each element of instancearray has a trailing newline
chomp it off
Code:
chomp @instancearray;
before passing it into foreach $line
 
Thanks, that has done the trick [thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top