FarTech has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys.

i am getting this error, which is due to line 132. $recall = system("c:/perl/sam/fasta34.exe -O $compare -Q $querry $library");

first time the system command runs perfectly fine, i dont know whats happening when it runs for the 2nd time

following is my code

can anybody please help me out

#!usr/bin/perl -w print"\n********Running Fasta34********** \n \n"; print"\n Please enter the file sequence \n"; my $seqfile = <STDIN>; #initial file querry sequence print "\n Please Enter the library file name \n"; #initial library my $library = <STDIN>; my @orgarr; my @inparr; my $recall; my $main = "c:/perl/sam/main.fasta"; #main.fasta stores the output to the fasta program $result = system("c:/perl/sam/fasta34.exe -O $main -Q $seqfile $librar +y"); if ($result >> 0) { warn "fasta34.exe ended with non-zero exit status \n"; } open(FASTA,"$main") or die "cant open the output file \n"; my $seqname; my $org = "c:/perl/sam/orginal.fasta"; #original.fasta stores the header and the sequences of all the matches + in fasta file my $input = "c:/perl/sam/input.txt"; #input.txt stores the header and the sequences of matches above cut o +ff print "Enter your cut off percentage"; $cut = <STDIN>; while (<FASTA>) { #compare the line of matching sequence if(m/>>(.{4,6})(.*)/) { $seqname = $1; $laterhalf = $2; } #print "SKIP A LINE iF A MATCH \n"; next if /^ini/; if (m/(\d+\.\d+)% identity/) { $per = $1; #check if match is above the cutoff percentage if ($per > $cut) { #print "\n\n$seqname$laterhalf \n"; #print "identity match $per % \n"; #store the first line of the input file open(ORG,">>$org"); open(INPUT,">>$input"); print INPUT ">$seqname$laterhalf \n"; print ORG ">$seqname$laterhalf \n"; #print all the sequences which matched the cutoff while(<FASTA>) { if (m/^($seqname)(.*)/) { #store the match sequence print INPUT "$2 \n"; print ORG "$2 \n"; } if(m/>>/) { #check if next sequence if so rewind one line back +"; seek(FASTA,-100,1); #break command last; } } print INPUT "\n"; print ORG "\n"; close(INPUT); close(ORG); } else { #printing all the sequences which is showed in fasta o/p f +ile open(ORG,">>$org"); print ORG ">$seqname$laterhalf \n"; while(<FASTA>) { if (m/^($seqname)(.*)/) { #store the match sequence print ORG "$2 \n"; } if(m/>>/) { #print "end of given loop"; seek(FASTA,-100,1); last; } } print ORG "\n"; close(ORG); } } } close (FASTA); open(ORG,"$org"); open(INPUT,"$input"); @inparr = <INPUT>; @orgarr = <ORG>; close(INPUT); close(ORG); $length=@inparr; print "length of inparr array is $length \n"; $querry = "c:/perl/sam/querry.aa"; $compare = "c:/perl/sam/compare.fasta"; $segcompare = "c:/perl/sam/segcompare.txt"; my $seqname1; my $laterhalf1; open(QUERRY,">$querry") or die "cannot open querry file\n"; open(SEGCOMPARE,">$segcompare") or die "cannot open segcompare file\n" +;; my $temp=0; while($temp<=$length) { while ($inparr[$temp] ne "\n") { print QUERRY "$inparr[$temp]"; $temp++; } $recall = system("c:/perl/sam/fasta34.exe -O $compare -Q $querry $ +library"); print "hi \n"; if ($recall > 0) { warn "fasta34.exe ended with non-zero exit status \n"; } open(COMPARE,"$compare")or die "cant open the output file \n"; while(<COMPARE>) { if(m/>>(.{4,6})(.*)/) { print SEGCOMPARE "\n"; $seqname1 = $1; $laterhalf1 = $2; print SEGCOMPARE "$seqname1$laterhalf1 \n"; } elsif (m/^($seqname1)(.*)/) { #store the match sequence print SEGCOMPARE "$2 \n"; } } my @segcomp = <SEGCOMPARE>; #$count++; #$temp++; } close(COMPARE); close(SEGCOMPARE); close(QUERRY);

Replies are listed 'Best First'.
Re: could not open c
by BrowserUk (Patriarch) on Feb 01, 2005 at 16:35 UTC

    This test:

    if ($result >> 0)

    should be

    if( ( $result >> 8 ) != 0 ) {

    Or more simply:

    if( $result >> 8 ) {
    If that doesn't fix your problem, then you will need to print out the failure code (print $result >> 8) and then look that up in the documentation for the executable to determine what the errorcode means.

    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
Re: could not open c
by cog (Parson) on Feb 01, 2005 at 16:42 UTC
    You might want to try printing the contents of $compare, $querry and $library to STDERR before the call to system. That might help tracking down the bug.

    Meanwhile, you should also consider adding use strict and use warnings to your code.

Re: could not open c
by borisz (Canon) on Feb 01, 2005 at 16:31 UTC
    I do not know if this change your error, but system return 0 on success. You test for > 0 somewhere but -1 is also a valid return value. See: system.
    Boris
Re: could not open c
by Animator (Hermit) on Feb 01, 2005 at 16:40 UTC
    Are you sure c:/perl/... works, it might depend on the win-platform you are using...

    Try with c:\perl\... (or c:\\perl\\... if you are using double quotes)