Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Sorting words, keeping only words that start with a letter and contain only letter characters, and hypens, and end in a letter

by Ido (Hermit)
on Nov 10, 2002 at 22:52 UTC ( [id://211811]=note: print w/replies, xml ) Need Help??


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}++;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://211811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found