Help for this page

Select Code to Download


  1. or download this
    my $str = "This is my program";
    my @words = split ' ', $str;
    
  2. or download this
    my @chunks = split /(\s+)/, $str;
    
  3. or download this
    shift @chunks if $chunks[0] eq '';  # and then
    my $s = $chunks[0] =~ /\s/ ? 1 : 0;
    my $e = $chunks[-1] =~ /\s/ ? -2 : -1;
    
  4. or download this
    my ($s,$e)=map $_ + ($chunks[$_] =~ /\s/ ?
        ($_ >=0 ? 1 : -1 ) : 0) => 0, -1;
    
  5. or download this
    map {s/[^a-z ]//gi} @words;
    
  6. or download this
    @words = map { (my $s=$_) =~ s/[^a-z ]//gi; $s } @words;
    
  7. or download this
    y/\0//d for @chunks;  # or @chunks[$e,$s];
    
  8. or download this
    for ([split /(\s+)/, $str]) {
        shift @$_ if $_->[0] eq '';
    ...
        local $"='';
        print "@$_";
    }