in reply to Inconsistent for the sake of convenience

Here's an ugly one, perhaps the ugliest of them all:
$x[12]=$x[123]=$x=$_=""; print "match one\n" if /$x[123]/; print "match two\n" if /$x[12]/;
The output is "match two".

See S_intuit_more in toke.c. Some quotes:
/* This is the one truly awful dwimmer necessary to conflate C and sed +. */ ... /* this is terrifying, and it works */ int weight = 2; /* let's weigh the evidence */ [almost 100 lines of scary code snipped] if (weight >= 0) /* probably a character class */

Replies are listed 'Best First'.
Re^2: Inconsistent for the sake of convenience
by codeacrobat (Chaplain) on Feb 17, 2009 at 21:26 UTC
    So totally awful, I'll have to clean it first.
    $ perl -MO=Deparse blurp.pl # normalize Code with B::Deparse $x[12] = $x[123] = $x = $_ = ''; print "match one\n" if /${x}[123]/; # array fail, characterclass win print "match two\n" if /$x[12]/; blurp.pl syntax OK

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});