in reply to How do I return false and set an error in special variable $!

The Errno module provides interface to the system error constants with magic %!. Since it's readonly, you can't just introduce new constants at will, unless perhaps, you subclass the module. But, you can use any predefined constant that is close to the error string you want to throw.
#!/usr/bin/perl use strict; use warnings; use Errno; sub usenumbers { my $var = shift; $var =~ /^\d+$/ or ($! = &Errno::EINVAL) and return; print "Yes, [$var] has numbers.\n"; return 1; } for (qw(1 4 haha)) { usenumbers($_) or die "$_: $!"; }
Results,
Yes, [1] has numbers. Yes, [4] has numbers. haha: Invalid argument at error.pl line 15.
However, I'm not sure this is a good practice. The problem is error constants are different across OSes.

Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!