Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

debug the error!!

by vnpandey (Scribe)
on Jun 20, 2000 at 13:17 UTC ( #18958=perlquestion: print w/ replies, xml ) Need Help??
vnpandey has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am trying to run the following programme & the errors I am facing while running are as follows:
syntax error at checkdataperl.p line 249, near "for" syntax error at checkdataperl.p line 250, near "++)" syntax error at checkdataperl.p line 286, near "}" Execution of checkdataperl.p aborted due to compilation errors.
Can you please let me know what is the error actually?????

#!/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 and 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"); 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 = "/xw" 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 pgask(false); for ($alloc=$allocin;$alloc<=60;$alloc++) { print ("\n",$alloc,"\n"); $i=0;$m=0;$p=0; print "\n We are checking data quality for hour=$hour Alocation= $a +lloc \n"; $astatname="/tmp_mnt/usr4/mrt/vinayPandey/name".$alloc.$hour."1.astat" +; $onedname="/tmp_mnt/usr4/mrt/vinayPandey/name".$alloc.$hour."1.1d" ; if ($comparison ne $hour) { $caldet="/usr4/mrt/vinayPandey/caldet".$alloc.$comparison."1.1d"; open(CALDET,$caldet); $c2=0; $line=<CALDET>; while( $line ne "" ) {chop($line); ($calqone[$c2],$calqtwo[$c2],$calqthree[$c2],$calqfour[$c2])=split(' ' +,$line,4); $line=<CALDET>; $c2++; } } if ((open(NAMEAS, $astatname)) && (open(NAMEONED,$onedname))) { while(<NAMEAS>) { ($arrone[$i],$arrtwo[$i])=split(' '); $i++; } close(NAMEAS); $n[1]=$i-1; while(<NAMEONED>) { ($arrthree[$m],$arrfour[$m])=split(' '); $m++; } } $n[2]=$m-1; close(NAMEONED); $k=0; for($p=0;$p<=$n[1];$p++) { for($n=0;$n<=7;$n++) { chop($arrone[$p]); } $corresonedname=($arrone[$p]."1d");$arrone[$p]=$arrone[$p]."astat.gz" +; if ( -e $corresonedname ) { for($j=0; $j<=$n[2];$j++) { if ( $corresonedname eq $arrthree[$j]) { $arronestore[$k]=$arrone[$p]; $arrtwostore[$k]=$arrtwo[$p]; $arrthreestore[$k]=$arrthree[$j]; $arrfourstore[$k]=$arrfour[$j]; if (open(NAME ,"$corresonedname")) { $g=0; while(<NAME>) { # Read data in 2 columns from file handle # and put in two perl arrays chop(); ($y[$g],$x[$g]) = split(/\s+/); $g++; } print ("\ng=",$g,"\n"); close (NAME); } $response="h";$r="f";$ab1=0; while ($response ne "abcde") { @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") { $y1=0;$y2=0.1;$fmin=$y[0];$fmax=$y[0]; for ($s1=0;$s1<($g-1);$s1++) { if ($fmax < $y[$s1]) { $fmax=$y[$s1]; } if ($fmin > $y[$s1]) { $fmin= $y[$s1]; } } print ("\n ymax=",$fmax,"Ymin=",$fmin,"\n"); $y1=$fmin; $y2=$fmax; $y2=($y2+0.1); $y1=($y1-0.1); print ("\n y2=",$y2,"y1=",$y1,"\n"); 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",$corresonedname); # Labels pgsci(5); # Change colour pgline($g,\@x,\@y); print("\n please enter your response for the plot....\n FOR SEEING +THE PLOT WITH MODIFIED AXES PLEASE ENTER n \n OR GIVE THE APPROPRIA +TE QUALITY FACTOR FOR THE FILE FROM 1-9\n ?"); $response=<STDIN>; chop($response); print ("you entered ",$response,"\n"); if ($response eq "n" ) { print ("\n Please enter Xmin value\n"); $abr1=<STDIN>;chop($abr1); if ($abr1 ne "") {$ab1=$abr1;} print ("\n Please enter Xmax value\n"); $abr2=<STDIN>;chop($abr2); if ($abr2 ne "") {$ab2=$abr2;} print ("\n Please enter Ymin value\n"); $yr1=<STDIN>;chop($yr1); if ($yr1 ne "") {$y1=$yr1;} print ("\n Please enter Ymax value\n"); $yr2=<STDIN>;chop($yr2); if ($yr2 ne "") {$y2=$yr2;} } elsif(("123456789" =~ m/$response/) && ($response ne "")) { $quality[$k]=$response;$response="abcde"; print ("\n aulaity ",$k,"=",$quality[$k],"\n"); } else { print "\n please enter proper response\n"; } } if ($comparison eq $hour) { $k++; goto NEXTLINE; } else { $hdiffer = &get_RAdiff_fromsun($comparison,$arrthree[$k]); if (($quality eq "1") && ($hdiffer >= 2)) { $calfilename=&gencalfn($corresonedname,$comparison) if (-e $calfilename) { $c2=$c2-1; for($c3=0;$c3<=$c2;$c3=$c3++) { if(($calfilename eq $calqname[$c3]) && ($calqfour[$c3] eq "1") && ($ca +lqthree[$c3]<=100)) { $gooddata="/usr4/mrt/vinayPandey/good".$hour; if (-e $gooddata) {open(FILE, ">>$gooddata"); } else { open(FILE,">$gooddata"); } $qnet=1; print FILE "$arrthreestore[$k] $arrfourstore[$k] $arrtwostore[$k] $qua +lity[$k] $calqone[$c3] $calqtwo[$c3] $calqthree[$c3] $calqfour[$c3] $ +qnet \n"; close(FILE); $k++; goto NEXTLINE; } else { if ($calfilename eq $claname[$c3]) { $c2++; $k++; goto NEXTLINE; } } } } } $k++; goto NEXTLINE; } } } } else { print "\n we are not able to find file $corresonedname\n"; } NEXTLINE: } if ( $comparison eq $ hour) { print "\n +++ k= $k"; $k=$k-1;print "\n +++ k= $k"; $calname="/usr4/mrt/vinayPandey/caldet".$alloc.$hour."1.1d"; if (-e $calname) { open(CALNAME, ">>$calname"); } else { open(CALNAME, ">$calname"); } for($c1=0;$c1<=$k;$c1++) { $hdifference=&get_RAdiff_forsun($comparison,$arrthreestore[$c1]); if ($hdiffernce < 2) { $quality[$c1]=$quality[$c1]+$W7; } print CALNAME "$arrthreestore[$c1] $arrfourstore[$c1] $arrtwostore[$c1 +] $quality[$c1] \n"; } close (CALNAME); } else { $k=$k-1; $c2=$c2-1; for($tak1=0;$tak1<=$k;$tak1++) { $calibname=&gencalfn($arrthree[$tak1],$comparison); $pos=&get_RAdiff_forsun($comparison,$arrthree[$tak1]); if (-e $calibname) {$W6=0;$factor="y";} else { $calibnamenew=$calibname; @newarr=("1a","2b","3c","4d","5e","6f","7g","8h","9i","10j","11k","12 +l","13m","14n","15o","16p","17q","18r","19s","20t","21u","22v","23w", +"24x"); for($st1=0;$st1<=6;$st1++) {chop($calibnamenew);} $b1=chop($calibnamenew); $b2=chop($calibnamenew); $b12=$b2.$b1; $jd1=chop($calibnamenew); $jd2=chop($calibnamenew); $jd3=chop($calibnamenew); $jday=$jd3.$jd2.$jd1; $nlm1=-1; $sn=chop($calibnamenew); $nl=0; while($nl != 5){ for ($ensure=1;$ensure<=2;$ensure++) {$nlm=$nlm1*$nl; $jday=$jday+$nlm; for ($na=1;$na<=4;$na++) { @subsubst=grep(/$na\S/,@newarr); $subsubst[0]=chop($subsubst[0]); for ($nah=1;$nah<=24;$nah++) { @hoursubst=grep(/$nah\S/,@newarr); $hoursubst[0]=chop($subsubst[0]); $caltestname=$calibnamenew.$subsubst[0].$jday.$b12."_".$hoursubst[0].$ +comparison."1.1d"; if (-e $caltestname) { $calibname=$caltestname;$factor="y"; if ($nl=0) {$W6=0;} elsif($nl<=3) {$W6=3;} else{$W6=5;} goto CHECK; } } } if ($nl eq "0") {++$ensure;} } $nl++; } if ($factor ne "y") {$calibname=$calqone[$tak2];} CHECK: for ($tak2=0;$tak2<=$c2;$tak2++) { if ($calibname=$calqone[$tak2]) { if ($calqthree[$tak2]<=100){$W4=1;} elsif ($calqthree[$tak2]<=400){$W4=2;} else{$W4=3;} if ($arrtwostore[$k]<=100) {$W3=1;} elsif ($arrtwostore[$k]<=400) {$W3=2;} else {$W3=5;} if ($pos >= 4) { $W5=1; } elsif ($pos >= 2) { $W5=2; } else { $W5=5; } $netquality[$tak1]=$W1*$quality[$tak1]+$W2*$calqfour[[$tak2]+$W3+$W4+$ +W5+$W6; $calstoreone[$tak1]=$calqone[$tak2]; $calstoretwo[$tak1]=$calqtwo[$tak2]; $calstorethree[$tak1]=$calqthree[$tak2]; $calstorefour[$tak1]=$calqfour[$tak2]; goto FIRSTLOOP; } } } FIRSTLOOP: } print ("\n here the actual test starts i.e. comparison etc.....\n" ); } NEXTLINETWO: } LABELEND: pgend; print("\n this is the end of the programme\n"); sub gencalfn { local(@complex,$temp,$calib1,$val1,$val2,$tempx,$tempy,@tempxy,$val3,$ +calib2,$comparison,$val4); @complex=("1a","2b","3c","4d","5e","6f","7g","8h","9i","10j","11k","12 +l","13m","14n","15o","16p","17q","18r","19s","20t","21u","22v","23w", +"24x"); $calib1=$_[0]; $comparison=$_[1]; for ($temp=0;$temp<=3;$temp++) { chop($calib1); } $tempx=chop($calib1);print"\n $tempx==",$tempx; $tempy=chop($calib1);print"\n tempy==",$tempy; @val1=grep(/\d{1,2}$tempx/,@complex);print "\n val1==",$val1[0]; @val2=grep(/\d{1,2}$tempy/,@complex);print "\n val2==",$val2[0]; @val3=grep(/\d{1,2}$comparison/,@complex);;print "\n val3==",$val3[0]; chop($val1[0]);chop($val2[0]);chop($val3[0]);print "\n ",$val1[0]," ",$val2[0]," ",$val3[0]; if ($val1 <3) {$val4=$val1+24-$val3;} elsif ($val1>$val3) {$val4=$val1-$val3;} if ($val2>$val4) { $val=$val2-$val4; @tempxy=grep(/$val\S/,@complex);print "\n ttt",$tempxy[0]; $tempxy[0]=chop($tempxy[0]);print "\n ttsfgsft=",$tempxy[0]; $tempxy[0]=$tempxy[0].$comparison;print "\n tttdjeo--=",$tempxy[0]; $calib2=$calib1.$tempxy[0]."1.1d"; } else{ if ($val1<$val3) {$val4=$val3-$val1;} elsif($val1>$val3) {$val4=24-$val1+$val3;} $val=$val2+$val4; @tempxy=grep(/$val\S/,@complex);print "\n ttt",$tempxy[0]; $tempxy[0]=chop($tempxy[0]);print "\n ttsfgsft=",$tempxy[0]; $tempxy[0]=$tempxy[0].$comparison;print "\n tttdjeo--=",$tempxy[0]; $calib2=$calib1.$tempxy[0]."1.1d"; } return ($calib2); } sub get_RAdiff_forsun{ local($jd,@daya_in_month,@avg_for_month;$RA,$change_in_jd,$shift_in_ye +ars,$comp,$value,$jd1,$jd2,$jd3,$jdtemp,$hourdiff,@arrcomp); @arrcomp=("1a","2b","3c","4d","5e","6f","7g","8h","9i","10j","11k","12 +l","13m","14n","15o","16p","17q","18r","19s","20t","21u","22v","23w", +"24x"); $comp=$_[0]; $jdtemp=$_[1]; for ($ltemp=0;$ltemp<=8;$ltemp++) {chop($jdtemp);} $jd3=chop($jdtemp); $jd2=chop($jdtemp); $jd1=chop($jdtemp); $jd=$jd1.$jd2.$jd3; @days_in_month = (31,28,31,30,31,30,31,31,30,31,30,31); @avg_for_month = (254,234,220,225,236,247,240,225,216,223,244,254) +; #$jd = "244" . "$jd" if( $jd >= 9000 ); #$jd = "245" . "$jd" if( $jd < 9000 ); $RA = 67434.075 ; #right ascension of sun on 1st January,1995. $change_in_jd = $jd - 2449717.5; $shift_in_years = 0; if($change_in_jd >= 365 && $change_in_jd <= 730) { $shift_in_years = 1; $change_in_jd = $change_in_jd - 365; $RA = $RA - 60; $days_in_month[1] = 29; } if($change_in_jd > 730) { $change_in_jd = $change_in_jd - 731; $shift_in_years = 2 + (int($change_in_jd / 365)); $change_in_jd = $change_in_jd % 365; $RA = $RA + 240 - ($shift_in_years * 60); } for($i=0;$i<12;$i++) { if($change_in_jd > $days_in_month[$i]) { $RA = ($RA + ($days_in_month[$i]*$avg_for_month[$i])) % 8640 +0; $change_in_jd = $change_in_jd - $days_in_month[$i]; } else { $RA = ($RA + ($avg_for_month[$i]*$change_in_jd)) % 86400; } } $value=(grep(/\d{1,2}$comp/,@comp))-0.5; if ($RA >$value) { $hourdiff=$RA-$value;} else{$hourdiff=$value-$RA;} return($hourdiff); }

janitored by ybiC exeedingly post-facto: Balanced <readmore> and <code> tags around long codeblock

Comment on debug the error!!
Select or Download Code
RE: debug the error!!
by le (Friar) on Jun 20, 2000 at 13:22 UTC
    Please: put your code into <CODE> tags. I really can't read what you put here. (See the Site HowTo.)
Re: debug the error!!
by toadi (Chaplain) on Jun 20, 2000 at 13:34 UTC
    Wow Obfuscated Code ...
    --
    My opinions may have changed,
    but not the fact that I am right

Re: debug the error!!
by t0mas (Priest) on Jun 20, 2000 at 14:47 UTC
    Kind of hard to read your code ;) but I think a ; is missing after
    $calfilename=&gencalfn($corresonedname,$comparison)
    but it's hard to tell. Try the code tags as le suggests.

    /brother t0mas
Re: debug the error!!
by turnstep (Parson) on Jun 20, 2000 at 15:34 UTC

    The short answer is that you have a bunch of syntax errors, simple things like closing parenthesis, misplaced quotes, etc. In particular, line 123

    $corresonedname=($arrone[$p]."astat.gz";
    is missing the closing parenthesis. Also, at line 251:
    $calfilename=&gencalfn($corresonedname,$comparison)
    does not have a semi-colon at the end - this is what was causing the start of the errors you reported.

    This is (at least) the second time you have posted to this site without properly formatting the code. Expect your post to be voted down heavily. There are still many other errors in your post after the two mentioned above. (A hint: check for balanced parens). I could write A LOT about the problems in your code, but you would do yourself a large favor by following a few guidelines:

    • Develop a consistent coding format, especially in regards to indenting. Indent two lines (or whatever you like, just be consistent) at the start of every block (i.e. after an opening '{' ) and add or remove indentation at the start and end of every block. This will really help to catch your syntax errors.
      $example="this_is"; if ($start_a_block) { print "Indent by two spaces\n"; print "And keep indenting until the blopck is done\n"; } for $x (@every_block) { print "Indenting goes in 2 spaces every time\n"; if ($another block) { print "Notice we are now inside two blocks, "; print "and have indented twice\n"; } print "Still inside the 'for' loop, so indent is 2\n"; }
    • Use a good editor (such as emacs (which is available on Windows as well!)) that can help you to balance parenthesis and curly braces automatically.
    • Look at other people's code (on this site, or, even better in a book like Learning Perl or Effective Perl Programming) which can show you a "better" way to do things. That way, you can learn why the following example lines, which still compile and are technically correct, could all be written better
      $hour=<STDIN>;chop($hour); for($n=0;$n<=10;$n++) {chop($calibnamenew);} for($c3=0;$c3<=$c2;$c3=$c3++)
      Since I listed them, I suppose it's only fair to show the better way as well:
      chop($hour=<STDIN>); for $n (0..10) { chop($calibnamenew); for ($c3=0; $c3<=$c2; $c3++) {
    • Don't use perl monks to help you solve syntax problems: try really hard to figure those out yourselves. I understand that your previous two problems might have been a little tricky to track down, but there are things you can do (besides wrapping your code in CODE tags) that will make it easier for us to track down the bug. Try commenting out parts of the code to narrow down the error. Try doing the same thing other ways and in other places. If the line reporting the problems looks correct (as it was in this case) start going backwards line by line, looking for simple things like a missing quote or a misplaced semi-colon.
    • Don't give up! That is a rather large program that you are attempting. It looks like you have a C background - train yourself to think in perl, not C (your 'for' loops gave you away) Clean up and format your code. When it runs without errors, run it with a -w. Then add 'use strict' to let perl *really* start digging for problems. Have patience and debug carefully. Study other people's scripts. Learn about the many ways of doing it. Eventually you will develop your own style. Study the online perldocs, especially in regards to the functions. Often times they include not just a description of what the function does, but good examples as well. Don't worry about getting flames on the site. Your post was badly formatted, but at least you asked a perl-related question, which is more than we can say about some of the posts here. :)
Joke
by Nitsuj (Hermit) on Aug 02, 2000 at 21:49 UTC
    This is some kind of joke, meant to be humorous, right?
    Or is this some kind of contest, the first guy to cut and paste it into a text editor and run some formatting on it and find the error wins.
    I rethought my post. I hope that I didn't sound cruel or something. I am sure that you are plenty smart and stuff, it just struck me as funny.

    Just Another Perl Hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://18958]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2014-10-21 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (106 votes), past polls