in reply to Re^2: how to count the no of repeats in a string
in thread how to count the no of repeats in a string

Too true! I had started with

our %counts; "$string," =~ /([^,]*),(?{ $counts{$1}++ })/g;

When that didn't work, I should have taken a step backwards, not a step forward (fixing the //g in scalar context).

Replies are listed 'Best First'.
Re^4: how to count the no of repeats in a string
by lodin (Hermit) on Nov 14, 2007 at 03:08 UTC

    A step forward (for some definition of forward) could've been

    local our %counts; $string =~ /(?:^|,)([^,]*)(?:,|\z)(?{ $counts{$1}++ })(?!)/;
    if one really wants to do it the regex way. ;-)

    lodin