perl crashes when searching

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babno
    New Member
    • Apr 2009
    • 10

    perl crashes when searching

    The console freezes and I get this error message when I search
    Perl Command Line Interpreter has encountered a problem and needs to close. We are sorry for the inconvenience.
    the array is loaded in from a file. the interesting thing though, is the error only comes up if the search is there. if it isn't then it works fine.
    Code:
    print"What is the section name";
    	$input=<STDIN>;
    	chomp($input);
    	$t=0;
    	$m=7;
    	$v=$i;
    	$v++;
    	while($t!=$i){
    		$result = @file[$t] =~ /$input/;
    		if($result){
    		$v=$t;
    		$m=2;
    		}
    		$t++;
    	}
    	if($m==7){
    	print"Section not found";
    	}
    	else{
    	print"Deleting Sectioin";
    	#delete
    	$t=$v;
    	$t++;
    	$w=1;
    		while($w=1){
    		if(@file[$t] =~ /Section/){
    		$w=0;
    		$delete=$t-$v;
    		}
    		$t++;
    	}
    		splice(@file, $v, $delete);
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    see any problem here?

    while($w=1){

    might be putting your computer into a tail spin.

    Comment

    • babno
      New Member
      • Apr 2009
      • 10

      #3
      indeed I do see a problem thanks. but as a matter of curiosity would that cause perl to crash? also print"Deleting Sectioin"; on line 20 never executes which is should since it is before the death loop

      Comment

      • Icecrack
        Recognized Expert New Member
        • Sep 2008
        • 174

        #4
        Another One

        while($t!=$i){

        Same as KevinADC said Tail Spin

        $i is never defined (given a value) so $t is never ever eq to $i to get out of the loop, i dont know if i missed something but hey i think thats your problem (I have not tested to see if this is true)

        Comment

        • babno
          New Member
          • Apr 2009
          • 10

          #5
          thanks for though $i is defined above and is the length of the array, sorry I forgot to mention that. that is just a small bit of my program which is over 400 lines long, thought it wouldn't be needed to post it all.

          and it goes through everything fine if there is no match, its when there is a match it just freezes and throws the error.

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            400+ lines and not using "strict"? No way to tell where the problem might be.

            Comment

            • babno
              New Member
              • Apr 2009
              • 10

              #7
              strict? my teacher is an idiot. also everything else works fine except when I try and search for something that is there

              Comment

              • Icecrack
                Recognized Expert New Member
                • Sep 2008
                • 174

                #8
                All I can suggest is some information from eWish

                Have a look at the perl doc's. They are very insightful.

                strict
                warnings
                scoping


                Using the strict and warnings pragmas is important. Also, learn what scoping is about too. These will help detect errors.

                Comment

                • babno
                  New Member
                  • Apr 2009
                  • 10

                  #9
                  thanks alot I will look

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #10
                    did you fix this yet?

                    while($w=1){


                    should be:

                    while($w == 1){

                    othewise the "while" loop may never end.

                    Comment

                    • babno
                      New Member
                      • Apr 2009
                      • 10

                      #11
                      been busy haven't been able to get into the lab, I will though

                      Comment

                      Working...