Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EOF in Perl.

Status
Not open for further replies.

heidi

Programmer
Jun 8, 1999
14
US
I'm having a problem with a Perl script that reads a file. Here's an outline of it:<br>
<br>
open FILENAME, "&lt;problemfile"); #Open password file.<br>
until (eofFILENAME)<br>
{<br>
$FileString = &lt;FILENAME&gt;; #Read line of data from file.<br>
&SplitString($FileString); #Split file string into two vars.<br>
<br>
#Compare user data with file data. If exists in file,<br>
#then pass on to wholesale screen.<br>
<br>
if (($LogOn{logname} eq $LogOnName) && <br>
($LogOn{logpassword} eq $LogOnPassword))<br>
{<br>
&SendToWholesale;<br>
}<br>
}<br>
&SendError;<br>
}<br>
<br>
The idea is that it checks to see if the ID and password entered by the user exist in a particular file. If so, it passes the user on to something else. If not, it should issue an error. It works perfectly, until it reaches the end of file, at which time it blows up. (I've tested, and it clearly is blowing up on the until line.<br>
<br>
Anyone have any help?<br>
<br>
-- Heidi<br>

 
I found the error of my ways. The problem was that I was reading past the end of the file. Funny - Perl didn't like that (for some odd reason). Nothing in the script that I showed above would indicate that fact, though.<br>
<br>
-- Heidi
 
You could say something like:<br>
<br>
open (FILENAME, "&gt;problemfile");<br>
while &lt;FILEHANDLE&gt;{<br>
<br>
..insert "stuff" here<br>
<br>
}<br>
<br>
This should only do "stuff" while there is things to read in the file.<br>
<br>
Disclaimer: I'm pretty much the newbie at Perl!! Don't shoot!! &lt;grin&gt;
 
Thanks, fellow newbie. I had tried that, but still ran into the same problem. By the way, FILENAME and FILEHANDLE should be the same. Also, the parentheses are a no-no. (I don't want to admit to how long it took me to figure that one out!)<br>
<br>
You're into the ISP group? It's quite likely that you would be a big help to me as I struggle through some of this. In general, programming is something I understand. Networks are another story.<br>
<br>
-- Heidi
 
something like this should do it.<br>
<br>
-- snip --<br>
#!/usr/local/bin/perl<br>
<br>
$input_file = 'filein.txt';<br>
$output_file = 'fileout.txt';<br>
<br>
open(INF,$input_file);<br>
open(OUTF,"&gt;$output_file");<br>
<br>
while(&lt;INF&gt;){<br>
print OUTF $_; <br>
}<br>
<br>
close OUTF;<br>
close INF;<br>
-- snip --<br>
<br>
This will copy everything from filein.txt to fileout.txt<br>
<br>
Regards<br>
<br>
Mike<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top