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

Why this code:
#! /usr/bin/perl -w use strict; use IO::Prompt; while (my $x = prompt "x: ", -while => '') {}
give me this warning?
Use of uninitialized value in pattern match (m//) at /usr/local/share/ +perl/5.8.8/IO/Prompt.pm line 91.
Thanks.

Replies are listed 'Best First'.
Re: IO::Prompt warning
by kyle (Abbot) on Jul 11, 2008 at 16:56 UTC

    I notice that the warning goes away if you use warnings instead of using the -w flag.

Re: IO::Prompt warning
by pc88mxer (Vicar) on Jul 11, 2008 at 16:47 UTC
    It's a bug. You get the same result if you run the while_until.pl example in the IO::Prompt distribution with use strict.

    The problem is that a next unless defined has to be added in the _get_prompt routine at this point (line 91):

    for (my $i = 0 ; $i < @data ; $i++) { local *_ = \($data[$i]); + next unless defined; if (ref eq 'HASH') { splice @data, $i + 1, 0, %$_; }
    The for loop removes arguments supplied to prompt by undef-ing them in the array @data, but the index $i still only advances by one. When an option with an argument is encountered, both the option switch and the argument are undef-ed, but the loop will still inspect the position occupied by the option's argument.
Re: IO::Prompt warning
by psini (Deacon) on Jul 11, 2008 at 16:41 UTC

    Maybe IO::Prompt doesn't like an empty pattern in -while argument. Anyway I think it is useless to specify it.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."