http://www.perlmonks.org?node_id=376362

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"')

  1. Don't reuse the method of solution of one exercise for any other.
  2. Don't make use of any external files (including modules).
  3. 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.

When posting comments, please protect spoilers and solutions from accidental viewing, for example using a black-box (<table bgcolor="#000000"><tr><td><font color="#000000">Text goes here</font></table>)

Have fun!


(not in order of difficulty)

Exercise 1: \$foo =~ /^[A-G]/ Exercise 2: \$foo =~ /^[H-N]/ Exercise 3: \$foo =~ /^\0/ Exercise 4: \$foo =~ /IO::Handle/ Exercise 5: \$foo =~ /IO::/ && $foo Exercise 6: \$foo[$[] == \$foo[$[+1]
Exercise 6 Update: \$foo[0] == \$foo[1] && !$[
Exercise 7: !eval { ($foo) = $foo } Exercise 8: !eval { [ @foo ] } Exercise 9: $foo && $foo =~ /^0\z/ Exercise 10: $foo =~ /^0\z/ && $foo Exercise 11: "$|" == 2 && $| == 0 Exercise 12: ($| = 1) == 2 Exercise 13: undef

Special thanks to mauke and woggle.

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.

UPDATE: Official solutions have been posted.