Solved

how do i read data from a file?

Posted on 1998-11-02
2
152 Views
Last Modified: 2010-03-04
I am using perl 5.003, IIS3 and NT4.0

I am desperately trying to get my web server to open a file and read data from it and print out what is read in using a perl script.

Here is what's happening;

This does not give me an error:
 
   print "line1";
   open (FH, "data.txt");
   $line2=<FH>;
   close (FH);

It simply prints 'line1' (as expected)

This does give me an error:

   print "line1";
   open (FH, "data.txt");
   $line2=<FH>;
   print "$line2";
   close (FH);

I get an error that says the "document contains no data"
It doesn't choke on opening, reading, or closing, but it seems to choke when i try to print out what i've read.
It won't even print out line1 when this happens.

What am i doing wrong?
0
Comment
Question by:johnsm
2 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1205892
Ignoring error codes, and forgetting that STDERR and STDOUT are not the same, nor are they buffered similarly? Try doing

$| = 1; # Get rid of this when you're done debugging.
print "Content type: text/html\n";
print "line 1\n\n";
open(FH, "data.txt") || die "Open failed: $!"
$line2 = <FH>;
close(FH);
print "$line2";


0
 
LVL 1

Author Comment

by:johnsm
ID: 1205893
thanks,
that worked fine.


0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now