barvin has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I'm using the following code to pipe my script output to less. This works, but when the script finishes my terminal is toast. It would do carrige returns and I can't see what I type. OSX. Any suggestions?
open (LESS, "| less") or die "Can't fork a process for less: $!"; print LESS "$accounts->{$account}{name}\n"; print LESS "\tUser: ", $accounts->{$account}{user}, "\n"; print LESS "\tPassword: ", $accounts->{$account}{password}, "\n"; print LESS "\tComment: ", $accounts->{$account}{comment}, "\n";

Replies are listed 'Best First'.
Re: open pipe
by jdporter (Paladin) on Apr 06, 2007 at 18:31 UTC

    First, you may need to exit the less program with q.
    Second, don't forget to close(LESS).
    Third, try executing system("stty sane") after that.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight
      First, you may need to exit the less program with q.
      Or use the -e switch with less.
        jwkrahn++

        That's what I love about this forum. You can always learn something new just by reading other's replies. I often set my mysql pager (/P) to /usr/bin/less so that I can scroll through large result sets. Using it with the -e switch makes this even more useful.

        Cheers,
        Darren :)

Re: open pipe
by barvin (Beadle) on Apr 06, 2007 at 20:04 UTC
    Thanks all. close LESS; did the trick. I always forget to explicitly close - that'll teach me to be sloppy!