Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Printing file to browser

by damian1301 (Curate)
on Apr 02, 2001 at 23:51 UTC ( #69103=note: print w/ replies, xml ) Need Help??


in reply to Printing file to browser

open(FILE,"file.txt") || die; print while <FILE>; close FILE;
Should do the trick. You have to print it on a line-by-line basis, which is what the while loop will do.

UPDATE: You all beat me to it, but mine took less space!! :)

Almost a Perl hacker.
Dave AKA damian

I encourage you to email me


Comment on Re: Printing file to browser
Download Code
Re: Re: Printing file to browser
by arturo (Vicar) on Apr 03, 2001 at 00:01 UTC

    Well, yes, but a) you didn't explicitly note the problem of not checking the return value of the call to open and b) you're wrong when you say it has to be done line-by-line -- either construct nysus tried should work (and does, on my system =)

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      You're right, it doesn't have to be printed line-by-line. But I would recommend it.

      The reason is that if the file is large, then the user will (usually) see what's been read and printed so far (assuming no caching, buffering, etc) if you do it line-by-line, but will have to wait until the whole file is processed if you do it as an array slurp. And, possibly, the connection might time-out durring the slurp if you're not careful.

      Of course, I could be totally mistaken. :-)

      bbfu
      Seasons don't fear The Reaper.
      Nor do the wind, the sun, and the rain.
      We can be like they are.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://69103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-08-21 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (139 votes), past polls