Solved

how do i read data from a file?

Posted on 1998-11-02
2
161 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 73
quoting a comma separated list 20 81
Perl File::Find alternative 1 50
Matching a random pattern with one common character 2 42
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

1 Experts available now in Live!

Get 1:1 Help Now