i have a program that takes in the directory of a file and reads it in. It then stores that file in an array. the user is given the option of which regular expression they would like to search for in the document once the user makes a selection it runs that part of code in the corrosponding if statment. Then the code is suppose to print every line from the document that contains the expression being searched for.
The problem is that the code does not print anything it is suppose to print each line of code that contains the expression being searched for but i get nothing when it is suppose to print i dont know if i have the wrong variable in the print in each of the if statements. can someone help!! please!
Code:print"Please Enter the absolute file directory of the file you wish to read\n"; $file = <STDIN>; open(file, $file); @file = <file>; print"\n1. Search for 'tion'\n"; print"2. Search for one or more 'e'\n"; print"3. Search for exactly 2 'e'\n"; print"4. Search for a user Defined expression\n"; print"5. Quit\n"; print"Your Selection: "; $select = <STDIN>; chomp($select); if($select == 1) { for($i=0; $i=scalar(@file); $i++;) { $result=@file=~/tion/; print"$result"; #print"1\n"; } } if($select == 2) { $result=@file=~/e+/; print"$result"; #print"2\n"; } if($select == 3) { $result=@file=~/e{2}/; print"$result"; #print"3\n"; } if($select == 4) { print"\nPlease Enter a pattern: "; $pattern=<STDIN>; chomp($pattern); $result=@file=~/$pattern/; print"$result"; #print"4\n"; } if($select == 5) { #print"5\n" print"GoodBye"; exit; }
Your code threw an error for me on line 14:
Then I realized that you had a ; after the $i++. I removed that and it worked fine for me. I'm surprised that your compiler did not throw a syntax error.Code:for($i=0; $i=scalar(@file); $i++;)
He has already been told of this error on another forum, he posted this same question on 4 or 5 forums, probably school work.
This is stilll wrong:
it should be:Code:for($i=0; $i=scalar(@file); $i++)
otherwise it will probably just go into an infinite loopCode:for($i=0; $i < scalar(@file); $i++)
I didn't even catch the middle assignment in the for loop. Good eye.
well, I had an advantage, I saw the question several times.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks