Help for this page

Select Code to Download


  1. or download this
    my $c = 0; s/-/$c++ < 3 ? '-' : ','/eg;
    
  2. or download this
    local our $c = 0; s/-(?(?{ $c++ < 3 })(?!))/,/g;
    
  3. or download this
    # As is, assumes at least 3 commas are found.
    my ($pre, $post) = /^((?:[^-]-){3})(.*)/s;
    $post =~ s/-/,/g;
    $_ = "$pre$post";
    
  4. or download this
    # As is, assumes at least 4 commas are found.
    my @parts = split(/-/, $_, -1);
    $_ = join(',', join('-', @parts[0..3]), @parts[4..$#parts]);
    
  5. or download this
    s/\|//; s/[|\s]+//g; my $c = 0; s/-/$c++ < 3 ? '-' : ','/eg;
    
  6. or download this
    s/\|//; s/\|/,/g; s/\s+//g; my $c = 0; s/-/$c++ < 3 ? '-' : ','/eg;