in reply to How can I reduce this with a REGEX?

You don't need to use regexes for this. In pseudocode:

use List::MoreUtils qw{uniq} while (<FH>){ chomp; convert each line to an array of numbers splitting by "-" sort the resulting list of numbers and apply uniq to this list: my @list_of_unique_items = uniq @list; join or print again each element followed by a "-" chomp again if needed to delete the last "-" undef the array process the next line

Replies are listed 'Best First'.
Re^2: How can I reduce this with a REGEX?
by misterperl (Friar) on Mar 14, 2014 at 17:06 UTC
    ..appreciate it guys but I'm trying to make this solution simpler & shorter- not longer!

    This isn't too bad I spose.. Seems to work in a 1-liner:
    s/(\d\d)((-\d\d)*?)(-\1)/$1$2/g while /(\d\d).*(-\1)/;
      Which can probably be further reduced to:
      $ cat 1078350.in 12-12 12-12-12 12-13-12-13 12-12-13-13 12-13-13-14 $ perl -pe '1 while s/(\d\d)(.*?)(?:-\1)/$1$2/g' 1078350.in 12 12 12-13 12-13 12-13-14
        $ perl -pe '1 while s/(\d\d)(.*?)(?:-\1)/$1$2/g' 1078350.in thanks I like this construct, never saw it before.. You got my ++ vote...