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

Good afternoon, I am trying to create a terminal based program (like CPAN). I am using Term::ReadLine to take care of the command line part of it and I am running into this error:

print() on closed filehandle FOUT at /System/Library/Perl/5.10.0/Term/ReadLine.pm line 193.
readline() on closed filehandle FIN at /System/Library/Perl/5.10.0/Term/ReadLine.pm line 301.
print() on closed filehandle FOUT at /System/Library/Perl/5.10.0/Term/ReadLine.pm line 203.

My code is
my $term = Term::ReadLine->new('Simple Perl calc'); my $prompt = "Enter your arithmetic expression: "; my $OUT = $term->OUT || \*STDOUT; while ( defined ($_ = $term->readline($prompt)) ) { my $res = eval($_); warn $@ if $@; print $OUT $res, "\n" unless $@; $term->addhistory($_) if /\S/; }
I have not found anything that explains what is going on/how to fix it and I am not sure where to go from here. I am running OS X 10.6.8. Thank you very much, Mike

Replies are listed 'Best First'.
Re: Term ReadLine in OS X
by kcott (Archbishop) on May 24, 2012 at 05:51 UTC

    I'm running Mac OS X 10.7.4 and can't reproduce your problem. I tried with both Perl v5.12.3 and Perl v5.14.2 - both produced:

    $ pm_readline_mac.pl Enter your arithmetic expression: 1+2 3 Enter your arithmetic expression: 8/2 4 Enter your arithmetic expression: exit $

    The only difference is the text I enter: under 5.12.3 it is emboldened; under 5.14.2 it is not.

    To run your code, I simply added the following lines before your code:

    use strict; use warnings; use Term::ReadLine;

    I recall that I initially had problems with CPAN prompts. Installing Term::ReadLine::Perl fixed the problem. Unfortunately, that was some time ago and I don't remember the exact nature of the problem; although, I don't recall getting warning messages. In the absence of other solutions, you could try installing Term::ReadLine::Perl if you don't already have it.

    When I was first looking at changing to a Mac, I asked: "Are there any major Perl issues with Mac OS X Lion?". I followed advice regarding installing a separate version of Perl: I took the Perlbrew path - others (MacPorts, ActiveState) are also suggested. You may want to consider these options before adding or updating modules used by your system Perl.

    -- Ken

      I installed Term::ReadLine::Perl and it fixed the problem. I also installed MacPorts. Now I am getting the error
      Cannot open /dev/tty for read at /Users/mike/readline.pl
      Thanks, Mike

        That sounds like you installed Term::ReadLine::Perl before MacPorts. Please advise the order of installations.

        Please also show the code in /Users/mike/readline.pl.

        As stated, I "took the Perlbrew path" - I don't have a lot of experience with MacPorts. The MacPorts Guide may be of use to you.

        -- Ken