in reply to conditional regex

Why make things so complicated? You want to match /[yY](?:[eE][sS])?/ ... but 'eq' is so much simpler ...

my $word = lc $_; print "yes\n" if $word eq 'y' or $word eq 'yes';
I think I need to make Occam's Razore my new .sig ... no one else seems to be defending the concept.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Replies are listed 'Best First'.
Re^2: conditional regex
by ikegami (Patriarch) on Aug 23, 2010 at 03:35 UTC

    chomp needed.

    I wouldn't necessarily call

    chomp( my $word = lc $_ ); if $word eq 'y' or $word eq 'yes';
    simpler than
    if /^y(?:es)?$/i;

    Maybe it's more complex to write, but surely it's simpler to read.

Re^2: conditional regex
by Old_Gray_Bear (Bishop) on Aug 23, 2010 at 11:32 UTC
    Simplicity is all in the eye of the Maintenance Programmer....

    ----
    I Go Back to Sleep, Now.

    OGB