Thanks to ihb for the inspiration:
/$(??{$`>=$X})/
It uses the $(...) syntax, which you might not recognize.
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Is $_ less than $X
by blokhead (Monsignor) on Jun 25, 2004 at 04:30 UTC
    Devious! ;)

    The most devious part is japhy's innocuous comment. $(...) syntax is hogwash!

    The $ starts the regex engine matching at the end of the string. Since $` is the portion preceding the current match, it gets set to the entire contents of $_.

    Now the (??{code}) zero-width assertion comes into play. $` >= $X is evaluated (as a string) and its result inserted into the regex. In Perl, boolean values stringify to "1" or "".

    So if $_ < $X, the comparison fails (returning ""), so the regex is simply /$/, which always succeeds. Otherwise, the comparison succeeds (returning "1"), and the regex is (equivalent to) qr'$1', which can never succeed.

    blokhead

      Kudos (not Kudra) to you, blokhead! I'm very pleased to see you've deciphered my little regex. I'd make extra accounts to ++ you multiple times if that were within my morality. ;)
      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;