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

I have this code chunk somewhere in a program I'm writing:

sub display { my $file = shift; my $plaintext = `gpg --decrypt $file`; open PAGER, "|less"; print PAGER $plaintext; close PAGER; }

gpg decrypts the file, I get the plaintext in $plaintext. Then I pipe it into less and less displays it fine. But the problem is that when the user exits less, the whole program quits with a "Broken pipe".

How can I solve that problem? No, I don't want to use the shell and simply write `gpg --decrypt $file | less`.

Replies are listed 'Best First'.
Re: How to page some text
by belg4mit (Prior) on Feb 18, 2002 at 00:22 UTC
    Read perlipc and trap SIGPIPE.

    --
    perl -pe "s/\b;([st])/'\1/mg"

      Thanks a lot, I learned about my problem and solved it.