[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] number ranges



Andy Bach wrote:
> I've got a module that give back lists of user responsibilites for case
> numbers using the last 2 digits, e.g.
> $mgr = 'andy'
>   if $case_no =~ /[0-4]5$/;
> $mgr = 'tina'
>   if $case_no =~ /[5-9]5$/;
> ...
> print "Manager is: $mgr\n";
> 
> I've a test that gives back all the case mgrs and their number
> ranges, but it looks like:
> andy: [01234]5
> tina: [56789]5
> 
> I'd like to have the [x-x] ranges back in the output, which I can do
> brute force-ish, but I have this nagging sense that there is a clever way
> to do it.  Any guesses?

it's not clever, but you can just put the pattern in
a string:

$ perl -le '
> $pat = "[0-4]5\$";
> /$pat/o && print "$_ $pat" 
>   for 25, 26, 35, 36, 45, 46, 47, 55, 56, 57;
> '
25 [0-4]5$
35 [0-4]5$
45 [0-4]5$

--
Steve Lane <sml@zfx.com>

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe