HEX
Server: Apache
System: Linux iad1-shared-b8-33 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User: samfetchero1 (10301780)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/share/doc/libio-prompt-perl/examples/require.pl
#!/usr/bin/perl

use IO::Prompt;

# The -require flag allows you to specify conditions that must be met by
# the input string...
#
# Each key of the hash is the error message to be printed if the corresponding
# value doesn't match the input. A %s in the error message is replaced with
# the current prompt.
#

prompt "next: ", -integer, -require => {
    'next (must be > 0):' => sub { $_ > 0 }
};
print "[$_]\n";

prompt "base: ", -i, -req => {
    '%s(an even number, please) ' => sub { $_ % 2 == 0 }
};
print "[$_]\n";

prompt "base: ", -req => { 'base [ACGT]: ' => qr/^[ACGT]$/ };
print "[$_]\n";

prompt "base: ", -req => { 'base [ACGT]: ' => [qw(A C G T skip)] };
print "[$_]\n";