how do make certain that no input (keyboard + mouse paste) is outsideof 7-bit ASCII in a perl script
Hi;
how do make certain that no input (keyboard + mouse paste) is outside
of 7-bit ASCII in a perl script?
Since I have no intention of correctly or completely handling input
that is outside of 7-bit ASCII, I thought it would be best to prevent
any characters outside of 7-bit ASCII from being input.
How best to do this?
I want to keep it simple.
Are there specific pragmas and/or modules that I can use to force this?
I'm looking at Programming Perl (3rd Edition), Perl Cookbook (2nd
Edition), cpan.org, etc, and I'm finding lots of stuff but it is
either too much (need some guidance) or not quite what I'm looking for
(confusing).
Let's say that I have only two kinds of prompted input:Yes/No question
and one numeric capturing regex.
If I compare the first letter of the response being either "Y" or "y"
then I can assume that any other response was a negative, even if it
was a 16-bit Unicode character?
Secondly, if I literally compare against digits and whitespace in my
capturing numeric regex, then anything outside of that I can
categorically reject?
Looking for the fishing pole more than the fish.
Thanks,
Ken Wolcott
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: how do make certain that no input (keyboard + mouse paste) isoutside of 7-bit ASCII in a perl s
At 17:08 -0800 01/02/2011, Kenneth Wolcott wrote:
>how do make certain that no input (keyboard + mouse paste) is outside
>of 7-bit ASCII in a perl script?
The regular expression means that from the beginning to the end of
the (chomped) input is either nothing or a string containing only
characters 32 to 126.
#!/usr/local/bin/perl
use strict;
print "Type something (type 'q' to exit) -> ";
while (<STDIN>){
chomp;
print "Bye!" and last if /^q$/i;
if ( /^[\040-\176]*$/ ){ # all from space to tilde
print "OK. '$_' is all us-ascii\n-> "
} else {
print "Can't accept '$_' ; " .
"contains non us-ascii characters\n-> "
}
}
JD
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
RE: how do make certain that no input (keyboard + mouse paste) is outside of 7-bit ASCII in a perl
From: John Delacour
> At 17:08 -0800 01/02/2011, Kenneth Wolcott wrote:
>
>>how do make certain that no input (keyboard + mouse paste) is outside
>>of 7-bit ASCII in a perl script?
>
> The regular expression means that from the beginning to the end of
> the (chomped) input is either nothing or a string containing only
> characters 32 to 126.
>
>
> #!/usr/local/bin/perl
> use strict;
> print "Type something (type 'q' to exit) -> ";
> while (<STDIN>){
> chomp;
> print "Bye!" and last if /^q$/i;
> if ( /^[\040-\176]*$/ ){ # all from space to tilde
> print "OK. '$_' is all us-ascii\n-> "
> } else {
> print "Can't accept '$_' ; " .
> "contains non us-ascii characters\n-> "
> }
> }
Your limited range is going to choke on the tab key.
Bob McConnell
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/