Thread: wrong variable?
View Single Post
  #1 (permalink)  
Old 04-03-2008, 08:22 AM
mtber mtber is offline
Newbie
 
Join Date: Nov 2007
Posts: 4
Credits: 0
Rep Power: 0
mtber is on a distinguished road
Unhappy wrong variable?

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;
}
Reply With Quote

Sponsored Links