(I posted this on my blog to keep up with my Iron Man quota, but since I got no comments there, I decided to re-post it here where I know people enjoy a good Perl puzzle.)

I'm working on a longer article about version numbers in Perl, why there are now so many ways to screw them up, and some recommendations. In the meantime, I realized that some of my examples for that article might be a fun puzzle for others with some curiosity and time to kill.

Format

Each puzzle consists of the output of several Perl one-liners using different versions of Perl. They are run in a directory with a single file, Foo.pm, like this:

package Foo; use strict; use warnings; our $VERSION = 1.23; 1;

In each puzzle, line 4 (the $VERSION line) is different and the puzzle is to figure out the $VERSION line given only the sample output.

Puzzle 1

$ perl5.10.0 -e 'use Foo 0.001001' $ perl5.8.9 -e 'use Foo 0.001001' Foo version 0.001001 required--this is only version 0.001001 at -e lin +e 1. BEGIN failed--compilation aborted at -e line 1. $ perl5.8.9 -Mversion -e 'use Foo 0.001001'

Puzzle 2

N.B. This puzzle intentionally requests a higher version number than is in Foo.

$ perl5.10.0 -e 'use Foo v0.1_1' Foo version v0.1_1 required--this is only version v0.0_1 at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl5.8.0 -e 'use Foo v0.1_1' Foo version v0.1.1 required--this is only version v0.0.1 at -e line 1 +. BEGIN failed--compilation aborted at -e line 1. $ perl5.6.2 -e 'use Foo v0.1_1' Foo version 0.011 required--this is only version 0 at -e line 1. BEGIN failed--compilation aborted at -e line 1.

Puzzle 3

$ perl5.10.0 -e 'use Foo 0.000001' Foo version 0.000001 required--this is only version v0.0_1 at -e line +1. BEGIN failed--compilation aborted at -e line 1. $ perl5.10.0 -e 'use Foo v0.0_1' $ perl5.8.9 -e 'use Foo v0.0_1' $ perl5.8.0 -e 'use Foo v0.0_1' Foo version v0.0.1 required--this is only version v0.0_1 at -e line 1 +. BEGIN failed--compilation aborted at -e line 1. $ perl5.6.2 -e 'use Foo v0.0_1' Foo version 0.001 required--this is only version v0.0_1 at -e line 1. BEGIN failed--compilation aborted at -e line 1.

Puzzle 4

$ perl5.10.0 -e 'use Foo v0.1.1' $ perl5.8.9 -e 'use Foo v0.1.1' $ perl5.10.0 -e 'use Foo v0.2.1' Foo version v0.2.1 required--this is only version v0.1.1 at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl5.8.9 -e 'use Foo v0.2.1' Foo version 0.002001 required--this is only version 0.001001 at -e lin +e 1. BEGIN failed--compilation aborted at -e line 1.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Perl version number puzzles by xdg

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.