more useful options | |
PerlMonks |
Returning string and numerical data types from subroutinesby saurabh.hirani (Beadle) |
on May 15, 2009 at 15:57 UTC ( [id://764298]=perlquestion: print w/replies, xml ) | Need Help?? |
saurabh.hirani has asked for the wisdom of the Perl Monks concerning the following question: Hi guys, I am writing a subroutine for daemonizing a process. Broadly speaking I've written it like this:
I call it this way
The problem with this is that the caller needs to do a "ne" check as it works for both 1 and error string. I would like to change the calling interface to:
But in the current implementation I can't use the desired way because if daemonize fails it returns an errstr which passes the "if (! daemonize)" test. I want to report the error, so I cannot return 0 on failure. I wanted to set the errstr in a way that $! does it - which is make the subroutine call more intuitive, like the way we use open or close
The best I can do is this:
so the usage is
which is better than the first way because I can use $isdaemon is both the string and numeric context and get my work done, but it still isn't as good as the way $! does it.
Back to
Seekers of Perl Wisdom
|
|