in reply to Sorting words, keeping only certain words

Sort is simply sort, that rest is a regex.
@newarray=sort grep /^[a-zA-Z]([a-zA-Z]*|-[a-zA-Z])*$/,@array;
HTH
Update: It's unclear whether you want words like 'b0n' (with characters that aren't letters in positions other than beginning and end), if you do, change the regex to:  /^[a-zA-Z]([^-]*|-[^-])*(?<=[a-zA-Z])$/
  • Comment on Re: Sorting words, keeping only words that start with a letter and contain only letter characters, and hypens, and end in a letter
  • Select or Download Code

Replies are listed 'Best First'.
Re: Re: Sorting words, keeping only words that start with a letter and contain only letter characters, and hypens, and end in a letter
by Anonymous Monk on Nov 10, 2002 at 23:03 UTC
    this is my code, can i not do this? it doesn't seem to filter any words out when i do.
    foreach $word (split){ if($word =~ /^[a-zA-Z]([a-zA-Z]*|-[a-zA-Z])*$/){ $count{$word}; }
    }
      Try $count{$word}=1;....
        yeah sorry i forgot the ++ after my $count{word}; it should be$count{word}++;