I've been putting silly things at the end of my modules for a while. There's no harm and its a little Easter egg. uny2k helpfully ends with "Yes, this code is a joke."
Class::Fields is chock full of them.
Taking it one step further, sometimes when a function is documented to return true
and false
I will return something other than 1 for true
. This is to punish people who write if foo() == 1
when they mean if foo()
. This was around the same period I was writing use constant TRUE => 1==1; use constant FALSE => !TRUE;
I have seen the return value of a module used in production code. I don't recall exactly why. The developer's logic was... tortured. I believe it was something along the lines of not wanting to have to write just one line instead of two. I don't remember why he didn't just export it.
This was the same developer who used %_
to pass arguments around (the *_
symbol is global across packages) and wrote 150 line map statements inside map statements.
The danger of using the return value, aside from obfuscation, is that it only works once.
$ cat Foo.pm
package Foo;
return "Basset hounds got long ears";
$ cat test.plx
#!/usr/bin/perl -w
print require Foo, "\n";
print require Foo, "\n";
$ perl -I. test.plx
Basset hounds got long ears
1
The first call to require
evaluates Foo.pm and returns the return value. The second call sees its already in %INC
and just returns true. And you can't even be sure that you're the first thing to require the code. You can get around this with do "Foo.pm"
but now you're reloading the module each time with warnings about redefined routines, problems for performance and possibly reinitializing globals. Its not worth it.