Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Regular Expression Question

by Aragorn (Curate)
on Dec 09, 2003 at 10:17 UTC ( [id://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"; # ... } } }
Arjen

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-19 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found