I'm not really sure if I understand all of your requirements: in fact I find your specifications slightly sloppy and incomplete. But if I do, then I'd just do something like this:
#!/usr/bin/perl -l use strict; use warnings; { my $state; sub fail () { $state++ } sub failed () { $state ? $state-- : $state } } LINE: while (<>) { chomp; my @chunks=split /_/; fail, next if @chunks < 2; my $oldch=''; for (@chunks) { /^([a-z])([a-z])\d*$/ or fail, next LINE; my $diff=(ord $2) - (ord $1); fail, next LINE unless ($diff == 0 or $diff == 1) and $oldch lt $_; $oldch=$_; } } continue { print "`$_': ", failed ? 'fails!' : 'succeeds!'; } __END__
UPDATE: I am greately ashamed to admit that the original code posted here contained an unncessary, clumsy chunk of code as for some reason I ignored a thing called 'transitive law' altogether... I updated the code above accordingly to remove at least that gross mistake. Incidentally I also changed C<le> to C<lt> which seems more appropriate.

Of course this may not be exactly what you're after, but I hope it's close enough that you can easily adapt it to your needs. Also this is intended to be a minimal example: you may want to give more informative output by e.g. making C<fail()> accept a message argument (and use it suitably somewhere).

Oh, and yes: at a certain point I used C<?:> (also) for its side effects, but I hope that in this case it's only a venial sin and that it will be forgiven...


In reply to Re: hash keys and regex by blazar
in thread hash keys and regex by state-o-dis-array

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.