I’d like to write a short Perl prg that has 1 parameter (a 3 digit integer) passed to it, and depending which list it’s a member of it returns the corresponding list’s number. How can I achieve this, also is there any way to put a range of number as an element in a list ?
::Returns 1,2,3,4 Depending on testNum passed
@gp1= (829,845,851,859,864,867);
@gp2= ("826-828","830-839","843-844","847-850","852-854","860-862","883");
@gp3= ("855-858",861,"863","865");
@gp4= ("877-882",884);
if ( ($ARGV[0]>=822 && $ARGV[0] <=824) || $ARGV[0] is membergp1)
{
return 1
}
if ( $ARGV[0]>=826 && $ARGV[0]<=828 || $ARGV[0] is memebr of group2
return 2
if $ARGV[0] is memebr of group3
return 3
if $ARGV[0] is memebr of group4
return 4
Three-digit numbers require an array of only one thousand elements. I suggest unpacking the data into an array and simply indexing that array with the passed parameter.
This program shows the idea. It expects the three-digit number on the command line.
output
Update
Alternatively you could check whether the passed parameter matches each range as you process it.
The output is identical to the previous solution.