|
||||||
| Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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;
}
|
| Sponsored Links |
|
|
|
|||||
|
Your code threw an error for me on line 14:
Code:
for($i=0; $i=scalar(@file); $i++;)
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
|
|||
|
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: Code:
for($i=0; $i=scalar(@file); $i++) Code:
for($i=0; $i < scalar(@file); $i++) |
|
|||||
|
I didn't even catch the middle assignment in the for loop. Good eye.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Don't hesitate to ask any questions that you have! Check out our ASCII Calculator! |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| wats the wrong with this code | simpatico | C and C++ | 9 | 03-06-2008 06:10 PM |
| Problems passing a serialized array in a session variable | gszauer | PHP Forum | 3 | 02-15-2008 11:18 AM |
| Using input to change a variable? | Plutonic | Java Help | 3 | 07-17-2007 04:02 PM |
| Java:Tutorial - The Variable | John | Java Tutorials | 0 | 12-09-2006 09:59 AM |
| Variable to Debug Window | Void | C# Programming | 3 | 07-04-2006 08:26 AM |