Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Perl

Perl Discussion for the PERL language - Practical Extraction and Reporting Language, is a programming language often used for creating CGI programs.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-2008, 08:22 AM
mtber mtber is offline
Newbie
 
Join Date: Nov 2007
Posts: 4
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;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-03-2008, 04:03 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 25
Posts: 4,512
Last Blog:
Zend: PHP Security Web...
Rep Power: 50
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: wrong variable?

Your code threw an error for me on line 14:

Code:
	for($i=0; $i=scalar(@file); $i++;)
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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-04-2008, 06:56 PM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 87
Rep Power: 6
KevinADC is on a distinguished road
Default Re: wrong variable?

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++)
it should be:

Code:
for($i=0; $i < scalar(@file); $i++)
otherwise it will probably just go into an infinite loop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-04-2008, 07:52 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 25
Posts: 4,512
Last Blog:
Zend: PHP Security Web...
Rep Power: 50
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: wrong variable?

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
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-05-2008, 01:13 AM
KevinADC KevinADC is offline
Learning Programmer
 
Join Date: Jan 2007
Posts: 87
Rep Power: 6
KevinADC is on a distinguished road
Default Re: wrong variable?

well, I had an advantage, I saw the question several times.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 05:47 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads