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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System () :Calling a subroutine 2

Status
Not open for further replies.

53712

Programmer
Sep 5, 2006
2
AT
Hello ,
I am having a Problem in calling another Script and i do not know where exactly the problem is .
I have Two scrips :
file.pl and system.pl

#!/usr/bin/perl
use strict;
use warnings;

# initialise
my %diff ;
my %diff1 ;
my %diff2 ;


my ($filename1, $filename2) = @ARGV;

@ARGV=2 or die "Usage : There should be 2 arguments";

open my $txt1,"< $filename1" or die "cant open '$filename1' for reading $!";
open my $txt2,"< $filename2" or die "Cant open '$filename2' for reading $!";
open my $txt3,"> added.txt" or die "cant open added.txt for reading $!";
open my $txt4,"> deleted.txt"or die "Cant open deleted.txt for reading $!";
open my $txt5,"> common.txt" or die "cant open common.txt for reading $!";



# create a hash table
while (<$txt2>)
{
$diff{strip($_)} = 1;
}

# extract added/deleted values

while(<$txt1>)
{
print $txt3 $_ unless (check_content($_) || !(eliminate(strip($_))));
}

close $txt1;
close $txt2;
close $txt3;

# extract added/deleted values

open my $txt8,"<".$filename1 or die "cant open $filename1 for reading $!";
open my $txt9,"<".$filename2 or die "Cant open $filename2 for reading $!";

while (<$txt8>)
{
$diff1{strip($_)} = 1;
}

while(<$txt9>)
{
print $txt4 $_ unless (check_content1($_) || !(eliminate(strip($_))));
}


close $txt8;
close $txt9;
close $txt4;


System.pl
#!/usr/bin/perl
use strict;
use warnings;
system('compare.pl','update_060904.txt','update_060905.txt')

The Program file.pl works out fine when it is executed seperately.However when it is called through another script i get an error saying
Cant exec "compare.pl" : No such file or directory at file.pl,line 6 (which is :system('compare.pl','update_060904.txt','update_060905.txt'))


would be gratefull for any advice

Laveena
 
Hello ,
Plz do not refer to my previous post as i have taken at times compare.pl,test.pl,....Plz refer to this following program.

compare.pl
#!/usr/bin/perl
use strict;
use warnings;

# initialise
my %diff ;
my %diff1 ;
my %diff2 ;

my ($filename1, $filename2) = @ARGV;

@ARGV=2 or die "Usage : There should be 2 arguments";

open my $txt1,"< $filename1" or die "cant open '$filename1' for reading $!";
open my $txt2,"< $filename2" or die "Cant open '$filename2' for reading $!";
open my $txt3,"> added.txt" or die "cant open added.txt for reading $!";
open my $txt4,"> deleted.txt"or die "Cant open deleted.txt for reading $!";
open my $txt5,"> common.txt" or die "cant open common.txt for reading $!";



# create a hash table
while (<$txt2>)
{
$diff{strip($_)} = 1;
}

# extract added/deleted values

while(<$txt1>)
{
print $txt3 $_ unless (check_content($_) || !(eliminate(strip($_))));
}

close $txt1;
close $txt2;
close $txt3;

# extract added/deleted values

open my $txt8,"<".$filename1 or die "cant open $filename1 for reading $!";
open my $txt9,"<".$filename2 or die "Cant open $filename2 for reading $!";

while (<$txt8>)
{
$diff1{strip($_)} = 1;
}

while(<$txt9>)
{
print $txt4 $_ unless (check_content1($_) || !(eliminate(strip($_))));
}


close $txt8;
close $txt9;
close $txt4;

test.pl
#!/usr/bin/perl
use strict;
use warnings;
system('compare.pl','update_060904.txt','update_060905.txt')

ERROR
Cant exec "compare.pl" : No such file or directory at test.pl,line 6 (which is :system('compare.pl','update_060904.txt','update_060905.txt'))

laveena
 
pass the path to perl, it's expecting it in the same directory as the script

Code:
system ("/usr/bin/perl compare.pl,update_060904.txt,update_060905.txt");
also takes the one argument in this instance, I think you're confusing the notation in the docs where they're using @args
Code:
system ("C:/Perl/bin/perl.exe compare.pl,update_060904.txt,update_060905.txt");
For Windows

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
also, this line is wrong:

Code:
@ARGV=2 or die "Usage : There should be 2 arguments";

you are using the assingment operator '=' to assign the value of 2 to the array instead of using '==' to check if the array has two elements, should be:

Code:
scalar @ARGV == 2 or die "Usage : There should be 2 arguments";





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top