Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how do i read data from a file?

Posted on 1998-11-02
2
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Six Sigma Control Plans

730 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