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

Report information
The Basics
Id:
58400
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
xenoterracide [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: -yes_no doesn't return true or false
#!/usr/bin/perl use strict; use warnings; use feature 'say'; use IO::Prompt; my $answer = prompt("what's my answer: ", -yes_no); say $answer; running this script with actually result in answer being yYnN depending on which character you entered.
Subject: Re: [rt.cpan.org #58400] -yes_no doesn't return true or false
Date: Wed, 16 Jun 2010 04:37:42 +1000
To: bug-IO-Prompt@rt.cpan.org
From: Damian Conway <damian@conway.org>
Hi Caleb
Show quoted text
> my $answer = prompt("what's my answer: ", -yes_no); > > say $answer; > > > running this script with actually result in answer being yYnN depending > on which character you entered.
That's right. It returns the input you typed encapsulated in an object whose Boolean value is true or false, depending on whether you typed [Yy] or [Nn]. So to get 0/1 out of it, you need either: say $answer ? 1 : 0; or: say !!$answer; (though that will actually print 1 or "", since those are the true/false values that the ! operator returns). Damian
Subject: Re: [rt.cpan.org #58400] -yes_no doesn't return true or false
Date: Tue, 15 Jun 2010 15:12:34 -0400
To: bug-IO-Prompt@rt.cpan.org
From: Caleb Cushing <xenoterracide@gmail.com>
it all seems quite cleaver to me... what's the point of returning the actual input here as opposed to just returning the boolean (which is what the docs seem to suggest). I can't see any reason to actually want whether I got a yYnN. but anyways I guess I can use those to do what I was trying to do. -- Caleb Cushing http://xenoterracide.blogspot.com
Subject: Re: [rt.cpan.org #58400] -yes_no doesn't return true or false
Date: Wed, 16 Jun 2010 05:28:17 +1000
To: bug-IO-Prompt@rt.cpan.org
From: Damian Conway <damian@conway.org>
Show quoted text
> what's the point of returning the > actual input here as opposed to just returning the boolean (which is > what the docs seem to suggest). I can't see any reason to actually > want whether I got a yYnN.
Maybe you want to know how eager they are? For example: 'y' vs 'YES!!!!!' ;-) The real reason is simply to be consistent. prompt() always separates the input (the string value returned) from the success status (the boolean value returned). For another example: if you just hit <ENTER> after a prompt, it returns an input of "" (empty string), but a success status of true. If the input and success were not consistently separated, that returned empty string would be treated as false, even though the input operation succeeded. All the best, Damian
I guess this is resolved...


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.