in reply to Open a Compressed File and Piping to More

open(STDOUT, '| more') or die;

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: Open a Compressed File and Piping to More
by Fletch (Bishop) on Mar 17, 2004 at 15:57 UTC

    Also keep in mind that if you might have other output after what's paged is done it'd be a good idea to keep the original STDOUT around.

    local( *SAVESTDOUT ); open( SAVESTDOUT, ">&STDOUT" ) or warn "Can't dup STDOUT: $!\n"; my $pager = $ENV{PAGER} || 'more'; open( STDOUT, "| $pager" ) or die "Can't open pipe to $pager: $!\n"; while( <COMPRESSED> ) { print "Wubba: $_" if /wubba/i; } close( STDOUT ); open( STDOUT, ">&SAVESTDOUT ) or warn "Can't dup SAVESTDOUT: $!\n";

    Or just use a different handle than STDOUT for your output to begin with (possibly using one-arg select() to change the default output handle as necessary).