in reply to seek() functionality on pipes
So long as you only need to go forward and always relative to the start of the file, then just discard as many bytes as necessary to reach the point you want:
use constant CHUNK => 4*1024; sub pseek { my( $p, $o ) = @_; read( $p, my $discard, $CHUNK ), $o -= $CHUNK while $o > $CHUNK; read( $p, $discard, $o-1 ); return $o; }
If you need to do relative or backwards seeks, you're pretty much out of luck unless you can afford to read the whole file into a scalar and then open that scalar as a file:
open MEM, '+<', \$bigscalar or die $!;
In which case you can treat the result just as you would a normal file.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: seek() functionality on pipes
by ikegami (Patriarch) on Jul 21, 2008 at 19:08 UTC | |
by BrowserUk (Patriarch) on Jul 21, 2008 at 19:22 UTC | |
by ikegami (Patriarch) on Jul 21, 2008 at 19:34 UTC | |
by BrowserUk (Patriarch) on Jul 21, 2008 at 19:46 UTC | |
by ikegami (Patriarch) on Jul 21, 2008 at 19:53 UTC | |
|
Re^2: seek() functionality on pipes
by HKS (Acolyte) on Jul 21, 2008 at 18:58 UTC | |
by BrowserUk (Patriarch) on Jul 21, 2008 at 19:32 UTC |