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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading from a file..

Status
Not open for further replies.

elegidito

Programmer
Jan 19, 2002
358
Code:
#!/usr/local/bin/perl 
$lfile = 'blah.txt';
# read file into var called buffer.
open(IPF,&quot;<$lfile&quot;) or die &quot;failed to open log file&quot;;
while (<IPF>) { $buffer .= $_; }
close IPF;
     print &quot;the $buffer&quot;;
    exit(0);
this is supposed to load the text file into $buffer -- i think -- and then print $buffer. it doesnt work...any help would be appreciated..im sure its a simple answer Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
I cut/pasted it into a new file on my machine, created a dummy log file, blah.txt and ran it. The output was the contents of blah.txt.
Works for me.

How exactly does it 'not' work?

What complaint do you get back from the OS or what behavior do you get from the perl code?

What OS are you running? 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
windows.

the problem is it wont even open the file :\ Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
The program is assuming that blah.txt is in the same directory as the program. If this is not the case it won't work. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
its in there. it opens the file when you write to it, but not when you want to read from it. (>> instead of <) Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
Hi ,
I think that the problem is in your PERL interpreter path !!
u have wrote : #!/usr/local/bin/perl
But in Windows OS, u have to make #c:\path_to_perl
hope yhat helps u !
 
oops im sorry, i gave my OS

the server OS is Redhat Linux 7.2

the path is correct because if i do something else it still works (well i think that makes the path correct. lol) Suceess, thats the way you spell success!
Got a question? Ask IMOZRMY!
 
u could check what is wrong with the file like this
Code:
$file &quot;full//path//to//file.file&quot;;
if (-e $file) { # file exist }
if (-s $file) { # file size > 0 }
if (-r $file) { # file is readable }
so in a cgi u could something like
Code:
if (-e $file) {
 if (-r $file) {
  # read here
 } else {
  # die here 'not readable'
 }
} else {
 # die here 'do not exist'
}
hope this helps
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top