I think the following comes pretty close to what you want (even more, multiple messages/ranges on a line and continued prompting):
#!/usr/bin/perl
use strict;
use warnings;
my $done = 0;
while (not $done) {
print "\n\nPlease type the numbers of the messages that are to be
+released (n-n and n \nare allowable, A for all): ";
my $input = <STDIN>;
chomp($input);
foreach my $range (split(/,/, $input)) {
$range =~ s/\s*//g; # Remove whitespace
if ($range =~ /[Aa]/) {
# All messages, assume we're done
print "All messages!\n";
# ...
$done = 1;
}
elsif ($range =~ /(\d+) # Single message number
(?: # Can be followed by a dash wit
+h a
-(\d+) # second number (which denotes
+the end
)? # of the range
/x) {
if ($1 and $2) {
print "Message range: #$1 to #$2\n";
# ...
}
else {
print "Single message: #$1\n";
# ...
}
}
elsif ($range =~ /[Qq]/) {
# Give the user the option to quit.
$done = 1;
}
else {
# Wrong input
print "Wrong input!\n";
# ...
}
}
}
Arjen
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|