Quantcast
Viewing latest article 2
Browse Latest Browse All 50

Re: A sort of perl golf challenge

Got it. This one’s in fact even shorter, heh.
sub collapse {
my $str = join ', ', @_;
$str =~ s/(\d+)(?:, ((??{$^N + 1})))+/$1-$^N/g;
return $str;
}
But I just noticed it’s buggy without the \b assertions your initial attempt had:
sub collapse {
my $str = join ', ', @_;
$str =~ s/\b(\d+)(?:, ((??{$^N + 1})\b))+/$1-$^N/g;
return $str;
}
PS.: it would be nice if tags were permitted in comments…

Viewing latest article 2
Browse Latest Browse All 50

Trending Articles