dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
Unfortunately, the regex only works if my set-bits are only in pairs. If I put the triple 1,1,1 (as above), it only works for the first pair. In addition, (1,1,1,0,1,1,0) converts to "1-2,3,5,6", which totally boggles me.my @channels = (1, 1, 0, 1, 1, 1, 0); my $val = join ',', map { $_ + 1 } grep { $channels[$_] } 0 .. $#chann +els; $val =~ s/(\d+),(\d+)/$1+1 == $2 ? "$1-$2" : "$1,$2"/eg; print $val, $/;
Help?
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: Question on s///eg
by Ovid (Cardinal) on Feb 27, 2002 at 17:19 UTC | |
|
Re: Question on s///eg
by japhy (Canon) on Feb 27, 2002 at 17:46 UTC | |
|
Re: Question on s///eg
by particle (Vicar) on Feb 27, 2002 at 17:25 UTC | |
|
Re: Question on s///eg
by PrakashK (Pilgrim) on Feb 27, 2002 at 17:27 UTC | |
|
Re: Question on s///eg
by zengargoyle (Deacon) on Feb 27, 2002 at 22:59 UTC | |
by japhy (Canon) on Feb 27, 2002 at 23:01 UTC | |
by zengargoyle (Deacon) on Feb 27, 2002 at 23:18 UTC | |
|
Re: Question on s///eg
by Sweeper (Pilgrim) on Feb 28, 2002 at 06:51 UTC |