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).
|