Skip Menu |

This queue is for tickets about the IO-Prompt CPAN distribution.

Report information
The Basics
Id: 56568
Status: open
Priority: 0/
Queue: IO-Prompt

People
Owner: Nobody in particular
Requestors: ipaetzold [...] gmx.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug: Use of uninitialized value $newlines
Date: Tue, 13 Apr 2010 21:15:03 +0200
To: bug-IO-Prompt [...] rt.cpan.org
From: ipaetzold [...] gmx.de
Hi there, I tried an example from the O'Reilly book "Perl best practices". Here's the code: while( 1 ) {     my $Choice = prompt 'Press key [a-e]: ', -onechar;     print "Pressed: $Choice\n"; } The output is with an unexpected error message: Press key [a-e]: aUse of uninitialized value $newlines in print at /usr/local/share/perl/5.10.0/IO/Prompt.pm line 465. Pressed: a Perl version: This is perl, v5.10.0 built for i486-linux-gnu-thread-multi OS version: Linux delta 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 05:23:09 UTC 2010 i686 GNU/Linux Thanks for notice. Ingmar -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
Subject: [rt.cpan.org #56568] Fix proposal
Date: Wed, 14 Apr 2010 20:15:59 +0200
To: bug-IO-Prompt [...] rt.cpan.org
From: Ingmar Pätzold <ipaetzold [...] gmx.de>
Hi there, 1) I forget to tell that I used #!/usr/bin/perl -w Without the "-w", the error message doesn't appear and it works fine. However, I'd like to use "-w" always. 2) There's a similar message when I press Backspace in my example: "Use of uninitialized value $input in length at /usr/local/share/perl/5.10.0/IO/Prompt.pm line 413." 3) A proposal for a fix: In Prompt.pm, function "get_input", I changed the following code: The first part (at line 417 in the current version 0.997) is responsible for the Backspace message since when pressing Backspace in one_char mode, $input doesn't seem to be defined, so calling "length" would break: elsif ($next eq $cntl{ERASE} and length $input) { substr($input, -1) = ""; print {$OUT} "\b \b"; next; } The second part at line 465 throws the message I've reported yesterday when pressing any other key in one_char mode. $newlines isn't defined, so it can't print anything and would complain: else { ReadMode 'restore', $IN; print {$OUT} $newlines; return $onechar ? substr($input, 0, 1) : $input; } Fixes: in both cases, I first check whether $input or $newlines, respectively, is defined. If yes, calling "length" is safe. elsif ($next eq $cntl{ERASE} and defined $input) { # <--- if (length $input) { # <--- substr($input, -1) = ""; print {$OUT} "\b \b"; } # <--- next; } [...] else { ReadMode 'restore', $IN; print {$OUT} $newlines if (defined $newlines); # <--- return $onechar ? substr($input, 0, 1) : $input; } Hope that's useful... Cheers, Ingmar
Subject: Re: [rt.cpan.org #56568] Fix proposal
Date: Wed, 14 Apr 2010 19:36:44 +0100
To: bug-IO-Prompt [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Thanks, Ingmar. Especially for the patch suggestions! I'm travelling at the moment, but will look into a fix as soon as I can (probably this week-end). Damian