Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Regular Expression Question

by Aragorn (Curate)
on Dec 09, 2003 at 10:17 UTC ( #313386=note: print w/replies, xml ) Need Help??

in reply to Regular Expression Question

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"; # ... } } }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313386]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2022-10-01 14:47 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.