Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/env perl
    use strict;
    ...
    original: This     is        a string with   variable     numbers   of
    +    spaces.
    cleaned:  This is a string with variable numbers of spaces.
    # of substitutions: 6
    
  2. or download this
    my $cleaned = $token->as_is;
    $cleaned =~ s/\s{2,}/ /g;  # I took out the /s modifier. I thought it 
    +was only for transliteration (e.g., $cleaned =~ tr/ //s).
    
  3. or download this
    my $cleaned = $token->as_is =~ s/\s{2,}/ /gr;