After the success of last year's edition, #perlhelp (EFnet) is proud to present... insaner than ever... the second round of How's your Perl? ! :-)

There are thirteen exercises this year. Each exercise consists of a predicate to be made true by a short snippet of code preceding the test. (For example, a simple way of checking your solution for an exercise is: perl -e '<solution>; <exercise> and print "ok!\n"')

Don't reuse the method of solution of one exercise for any other.

Don't make use of any external files (including modules).

No tie() and no bless().

All exercises have been tested with perl 5.8.*, and solutions do not necessarily have to work with any other version. Don't hesitate to use deprecated or experimental features, or depend on implementation details or even bugs, but avoid platform dependencies.

UPDATE: Apparently the notion of taking advantage of a yet-to-be-fixed bug is controversial. I therefore note that only 8, 11, and 12 are fishy in this regard, the other exercises are definitely solvable without exploiting bugs.

UPDATE: Minor rephrase of instructions for clarity.

UPDATE: Cool! ambrus and wog found an innovative way of solving 8 without exploiting a bug! :-D

UPDATE: Official solutions will be posted on monday. Until then there are hints below.

Confirmed on 5.6.1, 5.8.0, 5.8.1, 5.8.3. Doesn't work on 5.8.4 and 5.8.5.
And I think it should not work, because $foo[$[] is the
first element and $foo[$[+1] is the second; I don't see how
$[ and $[+1 can refer to the same element.

All exercises have been tested with perl 5.8.*, and
solutions do not necessarily have to work with any other
version.

Hm, strange.. I actually wrote $foo[$[] in the assuption this would prevent any $[-fiddling and force the real solution, but it seems $[ really doesn't work properly in perl: perl -le '$[ = -1; @x = (42); $y = 0; print $x[$y]' prints 42 for me on 5.8.3 and 5.8.4...

I'll add a note to the exercise that the intention is to solve it without diddling $[

Fair enough. My only excuse is that 5.8.3 is the only version I have, and that the other way seemed too similar to one of the solutions from last time around so I wanted to try something different :) I was trying to use the fact that $foo[-1] is the last element in the array, so if the array only has one element ...

Official hints:

[all]

There are two "wildcard solutions" that each can be used to solve nearly all of the exercises. Due to the no-reuse rule you can use each of them only once, and they're officially used for exercises 3 and 13.

[1-5]

Just explore all kind of scalar references. If you're really desperate you can plow through Perl_sv_2pv_flags() in sv.c in the perl source code to see exactly how references get stringified.

[3]

Good candidate for wildcard one: Find a way to override the meaning of the regex.

[4,8]

The pattern of exercise 4 is misleading, but the search down this incorrect path may reveal the solution to exercise 8. Exercise 4 is actually simpler than you'd think.

[5]

A fairly recent and unknown class of built-in objects.

[6]

Alias. (Last year there was a similar one which could be solved by manipulating $[. I tried to prevent that this year, though initially without success)

[7]

Make modification fail.

[8]

Find something that fails to get assigned anywhere. See also hint about 4 and 8 above. The ability to acquire this thing at all is most likely a bug.

[9]

Subtly perturb the meaning of the regex.

[10]

Have $foo change as a result of the first part of the predicate test.

[11]

Find a way to scribble onto $| so rudely it never gets properly turned into 0 or 1. This mechanism is most likely a bug.

[12]

Find a variable that ignores being assigned to. This behaviour is most likely a bug.

[13]

The best spot for wildcard two: A feature was added in 5.8 with which you can modify constants.