Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: displaying pdf

by alfie (Pilgrim)
on Oct 21, 2002 at 19:44 UTC ( #206913=note: print w/replies, xml ) Need Help??


in reply to displaying pdf

I wouldn't use the lineread mode with <FILE> for that, it might end bad. I am not sure but I guess that is your problem.

Rather try the following thing, which works perfectly for me with .jpg files:

while (read FILE, my $data, 1024) { print $data; }

You can of course vary the length of your read buffer in the while loop to your likes, to optimize memory usage/speed.

HTH & HAND.
--
use signature; signature(" So long\nAlfie");

Replies are listed 'Best First'.
Re: Re: displaying pdf
by nothingmuch (Priest) on Oct 21, 2002 at 21:22 UTC
    May i suggest replacing read with sysread, and 1024 with the value returned from (stat($file))[11]?

    The reason for doing so is that read is already buffered, and you're buffering it a second time... You should avoid it as you probably don't need it, and read directly...
    About the size - "11 blksize preferred block size for file system I/O " - to quote from perldoc -f stat

    open FILE,$file or die "$!"; my $len = (stat($file))[11]; while (sysread FILE, my $data, $len){ syswrite STDOUT, $data };
    Would be my code of choice.
    print is also bufferred I/O, and in the family of read, write, readline, getc, eof, printf seek and tell. It is also bufferred. It may or may not be a good idea to use buffering for writing either. Probably the latter if you're on the same filesystem.

    I think that the most commonly used buffer size in pipes is 4096 bytes, and there's probably a reason for it too.

    -nuffin
    zz zZ Z Z #!perl

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-01-21 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?