in reply to Sorting words, keeping only certain words

No attempt a golf, but clear I think.

#! perl -sw use strict; while (<DATA>) { chomp; print sprintf('%-20s', $_), (/^[a-z][a-z-]+?[a-z]$/i and not /--/) ? ' is ' : ' is not ', 'a valid word according to the rules specified.', $/; } __DATA__ brian0 brian- -brian bri--an Bria-n br-i-an brian

P.S. There's no need to put the whole question in the title:)


Nah! You're thinking of Simon Templar, originally played (on UKTV) by Roger Moore and later by Ian Ogilvy
  • 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

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 tachyon (Chancellor) on Nov 10, 2002 at 23:06 UTC

    This will fail on valid edge cases words like 'Oh no I no go OK' as your minimum valid word length is 3 chars. A small bit of modification will cover all cases:

    my @data = sort grep { /^[a-z][a-z-]*[a-z]$/i && ! /--/ || /^[a-z]$/i +} <DATA>;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print