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

maybe you'll consider hashes?
while(<DATA>){ %h = (); undef $h{$1} while(s/(\d\d)//); print join ("-", sort keys %h),"\n"; } __DATA__ 12-12 12-12-12 12-13-12-13 12-12-13-13 12-13-13-14
updated
$h{$1} = null became undef $h{$1}
thank you Mr. choroba

Replies are listed 'Best First'.
Re^2: How can I reduce this with a REGEX?
by choroba (Cardinal) on Mar 15, 2014 at 11:15 UTC
    I would also use matching instead of substitution. You mentioned in a private message that the substitution is faster (using such a trick would be worth a comment), but my benchmark doesn't show the effect. To speed things up, rather use my %h instead of %h = (). Output:
    Rate lenno choro lenno 25358/s -- -4% choro 26458/s 4% --

    Perl 5.16.2, x86_64-linux-thread-multi.

    Update: Significantly faster: use a hash slice undef @h{m/\d\d/g}; instead of the inner loop.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Yes, thank you for your reply, I apparently got mistaken,
      I'm deeply sorry. You were right.
      My results:
      use Benchmark(cmpthese); cmpthese(1000000, { 'a' => sub { $_ = '12-12-12-12-12'; undef $h{$1} while (s/(\d\d)//); }, 'b' => sub { $_ = '12-12-12-12-12'; undef $h{$1} while (m/(\d\d)/g); }, 'c' => sub { $_ = '12-12-12-12-12'; undef @h{m/\d\d/g}; } });
      results:
      Rate a b c a 195427/s -- -19% -35% b 241896/s 24% -- -20% c 300933/s 54% 24% --