Subject: | problem with $_ undefined when used in module |
Date: | Fri, 7 Aug 2009 14:19:52 +0100 (BST) |
To: | bug-IO-Prompt [...] rt.cpan.org |
From: | Martin L Jones <mlj [...] sabreit.co.uk> |
To replicate the fault:
====
#!/usr/bin/perl -w
use warnings;
use strict;
Demo::demo();
package Demo;
use IO::Prompt;
sub demo {
my $password = prompt 'Password: ', -echo => '*';
print $password;
}
1;
====
Error message is:
Use of uninitialized value in pattern match (m//) at
/usr/local/share/perl/5.8.8/IO/Prompt.pm line 91.
Password:
===
Don't entirely understand the cause, but adding the line marked '++'
below appears to be a workaround:
for (my $i = 0 ; $i < @data ; $i++) {
local *_ = \($data[$i]);
++ next if (not defined $_);
if (ref eq 'HASH') {
Thanks again for a very useful module!
Martin.