Perl version number puzzles

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 line 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 line 1.
BEGIN failed--compilation aborted at -e line 1.
This entry was posted in perl programming and tagged . Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. david
    Posted July 19, 2009 at 7:40 am | Permalink

    Since it's been over a month with no one guessing, and since rafl on #corehackers asked to see the answers, here they are:

    Puzzle #1: our $VERSION = v0.1.1;

    Note that for Perl 5.8.9, you need to hope that any users don't try to use() your module with a numeric conversion, the way they have been taught to do for perl. I.e. "use 5.006002" instead of "use v5.6.2".

    Puzzle #2: use version; our $VERSION = version->new(v0.0_1)

    Puzzle #3: use version; our $VERSION = version->new("v0.0_1");

    Note the only difference between these two is whether the v0.0_1 is in quotes in the call to new().

    Puzzle #4: our $VERSION = "0.001001";

    Sort of a trick question, but note that perl 5.10 reports "this is v0.1.1" which isn't actually what is in $VERSION.

© 2009-2014 David Golden All Rights Reserved