Current location: Hot Scripts Forums » Programming Languages » Perl » File Handling ! Why oh why can't I get it to find EOF


File Handling ! Why oh why can't I get it to find EOF

Reply
  #1 (permalink)  
Old 11-22-03, 11:44 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
File Handling ! Why oh why can't I get it to find EOF

I have a html page that looks to a file that contains a sentence of info. The page has worked for me when I put END at the end of this txt file but I found out I cant use this as Im appending to the file later on. Heres my script that worked...

open (POSTINFO,"<GeneralBoard.log");
while ($BoardDetails ne "END")
{

$BoardDetails=<POSTINFO>;
print $BoardDetails;

}

close (POSTINFO);

and the txt file format
DAL : Message board title : Date : Time
DAL1 : Message board Title : Date : Time
...
...
(...ect)
END

Ive had to replace it with this;

open (POSTINFO,"<GeneralBoard.log");
while (<>)
{

$BoardDetails=<POSTINFO>;
print $BoardDetails;

}continue{
close ARGV if eof;
}
close (POSTINFO);

and the txt file format
DAL : Message board title : Date : Time
DAL1 : Message board Title : Date : Time
...
...
(...ect)


----------------
But I keep getting either server errors or the information contained within the txt file doesnt show. Why cant it just read the file until there is nothing more to read. Ive never had a problem with this with any other language but perl obvously does things a little different than Im used to.

Ive tryied things like this;
open (POSTINFO,"<GeneralBoard.log");
while (POSTINFO ne eof)

open (POSTINFO,"<GeneralBoard.log");
while ($BoardDetails ne "")

open (POSTINFO,"<GeneralBoard.log");
while (!eof)


can anyone correct my code on the end of file peramaters.

Thanks
DAL

(ps does anyone have problems clicking on the smiles in the post new thread screen?...I keep getting errors with it) =S


MY LIFE IS FULL OF ERRORS! =(
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #2 (permalink)  
Old 11-22-03, 12:15 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Hi DAL,

Try this:

Code:
my $file = 'data.dat';
open (POSTINFO,"<$file") or die "Unable to read open $file.  Reason: $!";
print while <POSTINFO>;
close (POSTINFO);
As long as you are trying to print the entire file, that will work. Check the perlopentut pod for more info.

~Charlie
Reply With Quote
  #3 (permalink)  
Old 11-22-03, 12:17 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
try like this:

open (POSTINFO,"<GeneralBoard.log");
while (<POSTINFO>)
{

$BoardDetails=<POSTINFO>;
print $BoardDetails;

}
close (POSTINFO);

you might also want to look into using Tie::File for working with text files
Reply With Quote
  #4 (permalink)  
Old 11-22-03, 01:47 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Sorted!

Sorted ! Cheers ppl =)
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #5 (permalink)  
Old 11-22-03, 01:50 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by DAL
Sorted ! Cheers ppl =)
What did you end up doing to get it working? Just in case anyone else comes along with the same type of problem.

~Charlie
Reply With Quote
  #6 (permalink)  
Old 11-22-03, 02:21 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
open (POSTINFO,"<GeneralBoard.log");
while (<POSTINFO>)
{

$BoardDetails=<POSTINFO>;
print $BoardDetails

}
close (POSTINFO);



I didnt try the other way by adding the file name into a variable as this doesnt ever change so it can be staticaly addressed open ie["<GeneralBoard.log");]

Thanks again ppl

It apears I was dumber than I look!
=D
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #7 (permalink)  
Old 11-22-03, 05:46 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah, I was being a little too generic in my example. I was testing it on a local file and was too lazy to change the file name Anyhow, glad you have it working.

Code:
open (POSTINFO,"<GeneralBoard.log") or die "Unable to read open $file.  Reason: $!";
print while <POSTINFO>;
close (POSTINFO);
~Charlie
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please I Need help before all my hair is gone! LisatheNovice Perl 6 11-22-03 03:05 PM
ZIP/RAR file comment/.diz/.nfo viewer script net4ward Script Requests 0 11-19-03 04:41 PM
New Web Host, New Problem! justchat PHP 2 09-29-03 02:39 PM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 09:43 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 04:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.