By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

perl crashes when searching

P: 10
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.
Expand|Select|Wrap|Line Numbers
  1. print"What is the section name";
  2.     $input=<STDIN>;
  3.     chomp($input);
  4.     $t=0;
  5.     $m=7;
  6.     $v=$i;
  7.     $v++;
  8.     while($t!=$i){
  9.         $result = @file[$t] =~ /$input/;
  10.         if($result){
  11.         $v=$t;
  12.         $m=2;
  13.         }
  14.         $t++;
  15.     }
  16.     if($m==7){
  17.     print"Section not found";
  18.     }
  19.     else{
  20.     print"Deleting Sectioin";
  21.     #delete
  22.     $t=$v;
  23.     $t++;
  24.     $w=1;
  25.         while($w=1){
  26.         if(@file[$t] =~ /Section/){
  27.         $w=0;
  28.         $delete=$t-$v;
  29.         }
  30.         $t++;
  31.     }
  32.         splice(@file, $v, $delete);
Apr 22 '09 #1
Share this Question
Share on Google+
10 Replies

Expert 2.5K+
P: 4,059
see any problem here?


might be putting your computer into a tail spin.
Apr 22 '09 #2

P: 10
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
Apr 22 '09 #3

Expert 100+
P: 174
Another One


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)
Apr 22 '09 #4

P: 10
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.
Apr 22 '09 #5

Expert 2.5K+
P: 4,059
400+ lines and not using "strict"? No way to tell where the problem might be.
Apr 22 '09 #6

P: 10
strict? my teacher is an idiot. also everything else works fine except when I try and search for something that is there
Apr 23 '09 #7

Expert 100+
P: 174
All I can suggest is some information from eWish

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


Using the strict and warnings pragmas is important. Also, learn what scoping is about too. These will help detect errors.
Apr 23 '09 #8

P: 10
thanks alot I will look
Apr 23 '09 #9

Expert 2.5K+
P: 4,059
did you fix this yet?


should be:

while($w == 1){

othewise the "while" loop may never end.
Apr 23 '09 #10

P: 10
been busy haven't been able to get into the lab, I will though
Apr 23 '09 #11

Post your reply

Sign in to post your reply or Sign up for a free account.