in reply to How do I return false and set an error in special variable $!
Results,#!/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 "$_: $!"; }
However, I'm not sure this is a good practice. The problem is error constants are different across OSes.Yes, [1] has numbers. Yes, [4] has numbers. haha: Invalid argument at error.pl line 15.
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|
|---|