# -- MeaningOfLifeTheUniverseAndEverything.pm -- package MeaningOfLifeTheUniverseAndEverything; use strict; sub _create { bless \(my $_42 = 42) } sub _value { 42 } use overload '0+' => \&_value, 'nomethod' => \&_create; sub import { overload::constant integer => \&_create, float => \&_create; } sub unimport { use Carp; croak "You can't get rid of the Meaning of Life, " ."the Universe, and Everything"; } q{ 32 }; __END__ =head1 NAME MeaningOfLifeTheUniverseAndEverything =head1 SYNOPSIS use MeaningOfLifeTheUniverseAndEverything; =head1 DESCRIPTION This module replaces all other numbers with the answer to the ultimate quesiton of life, the universe and everything throughout the program it is run from. =head1 NOTE It is a fatal error to attempt to get rid of the meaning of life, the universe and everything. =head1 BUGS This module cannot turn nothing (a literal 0) into the answer. This is of course perl's fault, since anything associated with HHGTG wouldn't have such obvious faults (unless the guide gets taken over by some evil company or something like that.) =head1 SEE ALSO I. =cut # -- test.pl -- #!/usr/bin/perl -w use strict; use MeaningOfLifeTheUniverseAndEverything; sub value { (defined $_[0]) ? $_[0] : 'undef'; } sub show { foreach my $expr (@_) { print $expr, " = ", value(eval $expr), "\n"; print "(error: $@)\n" if $@; } } show split /\n/ => <<'END'; 4.2 * 10 4.2 * 9 + 1 2 + 2 42 - 1 3 % 2 0 END