Advertisement

05.02.2008 at 01:59PM PDT, ID: 23372996
[x]
Attachment Details

Grep - removing a range of numbers

Asked by csnell in Perl Programming Language

Tags: Perl

I currently have the following piece of code to delete numbers from an array:
@greparray = grep(!/$stringdelete/, @inputarray);
The user specifies the numbers to delete on the command line. I'm using Getopt::Long so $stringdelete becomes the numbers e.g. they type -o 100 110 200. I have a few small problems:
1) I need to allow the user to delete a range of numbers e.g. by typing 100-200 any number inbetween that range will be deleted. I've tried a number of things like 100..200 but i'm stuck.
2)I would also like the user to be able to type >100 and all numbers above 100 will be deleted. Or they can type <100. I've tried putting >100 but that doesn't work.
3) Also, a really small question I should know how to do. At the moment the user has to put the numbers in double quotes "100 200". Otherwise it will only delete the first number.
It's not a big problem but I'm thinking that my user might forget the double quotes every now and again and then wonder why it hasn't worked. How do I add a " at the start and end of the string so the user doesn't have to. Start Free Trial
 
 
[+][-]05.02.2008 at 02:04PM PDT, ID: 21490036

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.02.2008 at 02:08PM PDT, ID: 21490057

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: Perl
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628