Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

debug the error!!!

by Anonymous Monk
on Jun 09, 2000 at 21:40 UTC ( #17376=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run the following programme: the programme runs till line 156 as expected opens the file in $corresonedname but when it goes to line 185 just comes ut ogf the while loop after executing it only once, although the file it is reading is having 3308 lines!! with new line charcter at the end of every line...
#!/usr/local/bin/perl print("\n \nWelcome !! Please input the response very carefully in thi +s programme whenever asked for \n Now please ensure that before running +the programme you have run the vp29apr programme for the corresponding hou +r & also the 1d files for the j or t hour as applicable are has also been +run upon \n Now please enter the hour for which you want to check the data quality (a,b,..x) \n?" ); $hour=<STDIN>;chop($hour); print("you entered ", $hour ,"\n"); $comparison=3;@arrone=();@arrtwo=(); @array=("o","p","q","r","s","u","v","w","x","a","b"); if ($hour eq "j") { $comparison=$hour; } elsif($hour eq "t") { $comparison=$hour; } else { for($n=0;$n<=10;$n++) { if($array[$n] eq $hour) { $comparison="t"; } } } if($comparison ne "t") { if($comparison ne $hour) { $comparison = "j"; } } print("\n the value of comparison is ", $comparison ,"\n"); print ("\n Please enter the allocation no. from which you want to chec +k the data (1-60) \n"); $allocin=<STDIN>;chop($allocin); print ("\n",$allocin,"\n"); #goto LABELEND; for ($alloc=$allocin;$alloc<=60;$alloc++) { print ("\n",$alloc,"\n");#goto LABELEND; $i=0;$m=0;$p=0; print ("\n We are checking data quality for hour=",$hour," Alocation=",$alloc,"\n"); $astatname="/tmp_mnt/usr4/mrt/vinayPandey/name".$alloc.$hour."1.astat" +; $onedname="/tmp_mnt/usr4/mrt/vinayPandey/name".$alloc.$hour."1.1d" ; print("\nastatname= ",$astatname,"\nonedname=",$onedname,"\n"); if (open(NAMEAS, $astatname)) { print ("I am inside the first loop\n"); while(<NAMEAS>) { ($arrone[$i],$arrtwo[$i])=split(' '); print ("\n",'arrone[',$i,']=',$arrone[$i],' arrtwo[',$i,']=', +$arrtwo[$i],"\n"); $i++; } } close(NAMEAS); $n[1]=$i-1; if (open(NAMEONED,$onedname)) { while(<NAMEONED>) { ($arrthree[$m],$arrfour[$m])=split(' '); print ("\n We are in the second loop \n"); print ("\n",'arrthree[',$m,']=',$arrthree[$m],' arrfour[',$m,']=',$ar +rfour[$m],"\n"); $m++; } } $n[2]=$m-1; close(NAMEONED); $/="astat.gz";$k=0; for($p=0;$p<=$n[1];$p++) { chomp($arrone[$p]); print ("\n",'arrone[',$p,']=',$arrone[$p],"\n"); $corresonedname=($arrone[$p]."1d");$arrone[$p]=$arrone[$p]."astat.gz" +; print("\n corresonedname name is=",$corresonedname,"\n"); if ( -e $corresonedname ) { print (" \n file $corresonedname exists"); for($j=0; $j<=$n[2];$j++) { print("\n corresonedname=",$corresonedname," arrthree[",$j,"]=",$arrt +hree[$j],"\n"); if ( $corresonedname eq $arrthree[$j]) { print("\n $corresonedname $arrthree[$j] the value of j=$j"); $arronestore[$k]=$arrone[$p]; $arrtwostore[$k]=$arrtwo[$p]; $arrthreestore[$k]=$arrthree[$j]; $arrfourstore[$k]=$arrfour[$j]; #use PGPLOT; # Load PGPLOT module #print "\nTesting simple point plot...\n\n"; #print "PGPLOT module version $PGPLOT::VERSION\n\n"; #pgqinf("VERSION",$val,$len); #print "PGPLOT $val library\n\n"; # "?" will prompt for device #$dev = "?" unless defined $dev; #pgbegin(0,$dev,1,1); # Open plot device #pgscf(2); # Set character font #pgslw(4); # Set line width #pgsch(1.6); # Set character height $response="h";$y1=0;$y2=70;$r="f";$ab1=0; while ($response ne "y") { @arrsidtime=("a","b","c","d","e","f","g","h","i", "j","k","l","m","n","o","p","q","r","s","t","u","v","w","x"); if ($r eq "f") { while( $hour ne $arrsidtime[$ab1]) { ++$ab1;$ab2=$ab1 + 1;$r="t"; } } #pgenv($ab1,$ab2,$y1,$y2,0,0); # Define data limits and plot axes #pglabel("X","Y","Data"); # Labels #pgsci(5); # Change colour # nlkwqjdexit; print("everything is right...."); if (open(NAME ,"$corresonedname")) #{ # print ("\n\n the file",$corresonedname," has been opened","\n"); #@infile = <NAME>; #print "@infile"; #print"\n"; #$x[0]=<NAME>; #print $x[0]; #print ("\n $x"); #$x = @infile; #print("number of fields ", $x, "\n"); #while(<NAME>){ #($ag, $ah, @ag1 ) = split(' ',@infile,3); print("check ", $ag, "ah" +, $ah, "\n"); #print ("\n ",@ag1); #print($infile[0]); #exit; #} #} { print ("\n\n the file",$corresonedname," has been opened...."); #exit; #$abc=<NAME>; #print $abc; #goto LABELEND; $g=0; while(<NAME>) { print ("\n THE value of J is=",$j,"\n"); print("reading..",$corresonedname,"\n"); # Read data in 2 columns from file handle # and put in two perl arrays ($y[$g],$x[$g]) = split(' '); #print("\n",$x[0],"\n"); #print("\ny=",$y[0],"\n z=",$z[0]); $g++; #$abc=<NAME>; } print("\n khadfhakfh AAAA"); if( $j==5) { #$aj=@x; print("the value of ele=",$x[5],"\n"); exit; #print("\n",$x[0],"\n"); #print("\n value of x=",$x[0]); print("\nYes it comes here from line 219\n response=",$response,"\n r= +",$r,"\n ab1=",$ab1,"\n g=",$g,"\n");goto LABELEND;} print ("\n",$g,"\n"); # Plot points - note how perl arrays are passed #pgpoint($g,\@x,\@y,17); #pgend; close (NAME); } $response="yn"; print("\n enter your reply\n"); $response=<STDIN>; chop($response); print ("you entered ",$response,"\n"); goto LABELEND; if ($response eq "n" ) { print ("\n Please enter Xmin value\n"); $ab1=<STDIN>;chop($ab1); print ("\n Please enter Xmax value\n"); $ab2=<STDIN>;chop($ab2); print ("\n Please enter Ymin value\n"); $y1=<STDIN>;chop($y1); print ("\n Please enter Ymax value\n"); $y2=<STDIN>;chop($y2); } } print("\n please Give the quality factor\n"); $quality[$k]=<STDIN>;chop($quality[$k]); if ($comparison eq $hour) { $k++; goto NEXTLINE; } else { print ("checking the data etc... if $ quality response is not 1 for + both file + calibarator it will just go to next file.. as here for ex.. +.\n"); # if qualit is one for both it prints the things in output file go +es # to the #next allocation else it just comes out of the loop.. $k++;goto NEXTLINE; } } print ("\n Hi Hi $j thtime no match value of j=$j\n arrthree= $arrth +ree[$j] \n the value of corresonedname= $corresonedname \n"); } } else { print ("\n we are not able to find file",$corresonedname,"\n"); } NEXTLINE: } if ( $comparison eq $ hour) { print ("\n here write all the files in good data output file note in one go for one allocation(60 for the whole hour & in each file many + file\n"); print ("it now goes to the next allocation\n"); goto NEXTLINETWO; } else { print ("\n here the actual test starts i.e. comparison etc.....\n" ); } NEXTLINETWO: } LABELEND: print("\n this is the end of the programme\n");

Replies are listed 'Best First'.
Re: debug the error!!!
by Ovid (Cardinal) on Jun 09, 2000 at 22:30 UTC
    You could try using the Perl debugger on this one. From the command line, type
    perl -d PROGRAM
    This starts your program with the Perl interactive debugger. Since your problem is at line 185, set a breakpoint at it once you are in the debugger.
    b 185
    Then 'c'ontinue the program and it will run until the breakpoint.
    The next line of code you will see is line 185. Note: the debugger displays the line of code about to be executed. Then, print the value the suspect variable(s) that name be causing the problem.
    p $variable1, " ", $variable2, " ", $variable3
    The spaces are to prevent the vars from being run together.

    Make sure you print them both before and after the code is run to see how they've changed. Particularly, print the value of any variables upon which a conditional depends.

    At this point, step through the problem area one line at a time to check it's execution.

    After stepping through each line, print out the value of the variables you wish to examine to see if anything is different from what you expect.
RE: debug the error!!!
by turnstep (Parson) on Jun 10, 2000 at 02:08 UTC

    Here's a problem (not the only problem, but probably the one you were looking for):

    $/="astat.gz";$k=0 ## About line 84

    Hrmmm...what is that doing there? $/ is the "Input Record Separator" and 9 times out of 10, the only thing you want to do to it is to undefine it (or set it to null). Basically, instead of separating any files read in after this by newlines, it separates it by the string "astat.gz" This is your problem - since the string "astat.gz" was not found in the file, it was read in a one long line. Quick fix: don't mess with $/.

      Thanks A lot!!! after reading the third reply I could successfully debug the error... Earlier comments really didn't help as I had already tried all of themm Thanks a lot!!!! bye!!
Re: debug the error!!!
by swiftone (Curate) on Jun 09, 2000 at 21:45 UTC
    I've put all sorts of general comments on the code below. I can't find your specific error, but following these style tips should help you find it yourself, or be more likely to get help in the future.
    Use perl -w to turn warnings on. Include "use strict;" to enforce variable declaration. See perlstyle for tips.

    There is no real reason to use chop()...get in the habit of using chomp(), and use chop() only when you really mean it.

    #goto LABELEND;
    I realize this has been commented out, but you should not have to use goto. A case can be made for when to use goto, but given perl's great flexibility in flow-control, you can plan to never use it and be fairly safe.

    if (open(NAMEONED,$onedname))
    You should always report error conditions on file opens. Try : open(NAMEONED, $onedname) or die "Can't open $onedname: $!";

    #use PGPLOT; # Load PGPLOT module #print "\nTesting simple point plot...\n\n"; #print "PGPLOT module version $PGPLOT::VERSION\n\n";
    When posting code and asking for help, remove all useless, commented out lines.

    $k++;goto NEXTLINE;
    This is somewhere where a goto is unnecessary. Look up line labels, next and last in perlman:perlsyn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://17376]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-06-25 14:23 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (567 votes). Check out past polls.