in reply to Re: IO::Prompt -- why isn't this working (menu with hashref)?
in thread IO::Prompt -- why isn't this working (menu with hashref)?
Personally, I'd go with:
sub shall_we { my $ans = prompt( "What'll it be?", -menu => { 'Yes, definitely.' => 1, 'No way.' => 0 }, ); return $ans ? 0+$ans : undef; }
not that I disagree with your expectation after a quick initial read of the docs
Or even after a thorough read. The returned object is not documented at all. From peeking at the source,
It has no methods.
It has a very weird destructor that clobbers $_ if you don't do one of the above before the object is destroyed. That allows the following to work:
sub shall_we { local $_; prompt( "What'll it be?", -menu => { 'Yes, definitely.' => 1, 'No way.' => 0 }, ); return $_; }
Update: Fixed ... : ... : ... that should have been ... ? ... : ...
|
|---|