Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 DamnDirtyApe (Curate)
on Nov 11, 2002 at 06:38 UTC ( [id://211868]=note: print w/replies, xml ) Need Help??


in reply to Sorting words, keeping only certain words

This appears to work as requested, and it's a whole lot easier to read than some of the other options. :-)

#! /usr/bin/perl use strict ; use warnings ; my @words = qw( brian0 brian- -brian bri--an Bria-n br-i-an brian ) ; print map { "[$_]" } @words ; print "\n" ; my @good = grep { /^[[:alpha:]]/ # Starts with a letter && /[[:alpha:]]$/ # Ends with a letter && ! /--/ # No consecutive hyphens } @words ; print map { "[$_]" } @good ; print "\n" ;

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche
  • 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
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found