Display ing the contents of a text file

angelsky
angelsky used Ask the Experts™
on
How can I display the contents in a text file? Thanks =)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Simple way:
-----------
open DATA, "text.txt" or die "Can not open text.txt $!\n";
while (<DATA>) {
   print $_;
}


Or long way, for printing to a webpage (could also use above and add the following line:
print "Content-type: text/html\n\n";

-------------
open(DATA,"text.txt");
 @txt = <DATA>;
close(DATA);
           
print "Content-type: text/html\n\n";
print <<EOF;
<HTML>  
<HEAD><TITLE>Contents Textfile</TITLE></HEAD>  
<BODY>
<p>
EOF

foreach $item (@txt) {
   print $item;
}

print <<EOF;
</p>
</BODY>
</HTML>
EOF

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial