Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Term::UI on Win32

by derimac (Novice)
on Mar 16, 2012 at 16:55 UTC ( [id://960021]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all,
This is my first post here in the forum.

$term = Term::ReadLine->new('selection'); $name = $term->get_reply(prompt => 'select a name', choices => \@arrayOfChoices); ...

On a Linux box this statement works fine without any pain. When I run the same script on a Win32 with ActiveState Perl 5.8 I can type my choices and then I got a message like this:
Cannot create second readline interface, falling back to dump.
The rest of the code is running fine but I don't want to see the message.
What can I do to get rid of this message?
Please can someone give me a hint what is going wrong? If have asked Mr. Google but nothing found what my issue had solved. Please, forgive me my Perl and English knowledge is not good
Thanks, Andreas

Replies are listed 'Best First'.
Re: Term::UI on Win32
by Marel (Initiate) on Mar 16, 2012 at 22:21 UTC
    Hi Andreas,

    If you have ActiveState Perl, why not try opening the HTML help, C:\Perl\html\index.html. if you followed the standard installation procedure. Now select in the left-hand pane the help for the Term::ReadLine module.

    If I look at this page I see that the Term::ReadLine module that comes with ActiveState Perl does not have a get_reply function...

    Okay, Activestate specific? No, just check this link.

    Next I asked mr. Google for "perl term get_reply" and found a post on stackoverflow and there I saw also Term:UI. So:

    use warnings; use Term::UI; use Term::ReadLine; my $term = Term::ReadLine->new( 'brand' ); my @arrayOfChoices = ( qw( Hans Jan Jannie Piet Klaas Truus ) ); my $reply = $term->get_reply( prompt => 'select a name', choices => \@arrayOfChoices, ); print $reply;

      Many thanks for your reply,
      I have checked the ActiveState HTML help and found that Term::UI supports get_reply on ActiveState. Term::UI took the @ISA array from Term::ReadLine to extend the functions. My assumption is that it should work on Win32 without this nasty message.
      As well I have seen this post on stackoverflow but this does not give an explanation of the message I got back.
      Thanks Andreas

Re: Term::UI on Win32
by furry_marmot (Pilgrim) on Mar 16, 2012 at 22:22 UTC

    You only gave a snippet of your code, so I can't even guess. But the example code in the docs work on my Win32 machine (Win7 Pro). Why don't you start with the example code and work your array in there. If that doesn't work, try posting the rest of your code so someone might have a chance of anwering your question.

    --marmot

      Hello marmot
      I found the problem. my script creates 8 different Term::ReadLine objects in different sub routines. The term object is created within each sub routine. It looks as you can only create a single object of Term::ReadLine in a single Perl script.
      If you try to create a second one then you get the message. If I use for these different input methods just a single object it works without the message on Windows. As I have said multiple Term objects are working fine on Linux and MacOSX but not on Windows.
      Do you have any idea why this is the reason?


      use Term::UI; use Term::ReadLine; my $term = Term::ReadLine->new('lang'); my $reply = $term->get_reply( prompt => 'What is your default prog. la +ng?', default => 'Perl'); my $term2 = Term::ReadLine->new('OS'); $reply = $term2->get_reply( prompt => 'What is your OS?', default => ' +MacOS');

      Any ideas?
      Thanks Andreas

        You can only create a single object of Term::ReadLine if the Term::ReadLine::Perl 'personality' is being used.

        Behold

        C:\tmp>perl foo.pl What is your default prog. lang? [Perl]: What is your OS? [MacOS]: C:\tmp>perl -I Term-ReadLine-Perl-1.0303\blib\lib foo.pl What is your default prog. lang? [Perl]: Cannot create second readline interface, falling back to dumb. What is your OS? [MacOS]: C:\tmp>

        And this limitation isn't just a MSWin32 thing:

        [canker:]$ perl foo.pl What is your default prog. lang? [Perl]: What is your OS? [MacOS]: [canker:]$ perl -ITerm-ReadLine-Perl-1.0303/blib/lib foo.pl What is your default prog. lang? [Perl]: Cannot create second readline interface, falling back to dumb. What is your OS? [MacOS]:

        Forcing Term::ReadLine to load the Stub personality should work fine.

        use strict; use warnings; BEGIN { $ENV{PERL_RL}='Stub'; }; use Term::UI; use Term::ReadLine; my $term = Term::ReadLine->new('lang'); my $reply = $term->get_reply( prompt => 'What is your default prog. la +ng?', default => 'Perl'); my $term2 = Term::ReadLine->new('OS'); $reply = $term2->get_reply( prompt => 'What is your OS?', default => ' +MacOS');

        And it does

        C:\tmp>perl -I Term-ReadLine-Perl-1.0303\blib\lib foo.pl What is your default prog. lang? [Perl]: What is your OS? [MacOS]: C:\tmp>

        And on a non-MSWin32 OS too

        [canker:]$ perl -ITerm-ReadLine-Perl-1.0303/blib/lib foo.pl What is your default prog. lang? [Perl]: What is your OS? [MacOS]: [canker:]$

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://960021]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found