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