in reply to An example of programming by contract

In perlvar, it is seen, $! is $OS_ERROR, that is, an error from the OS. I presume that your program is not the OS... you can't set $! AFAIK. I presume that you want to have error messages other than the standard ones from the OS, which you can't get from $! AFAIK. There is a way to set $@ to whatever you wish, though: by dieing. Other than that, I see no other way to signal errors, other than maybe making the return value an object which stringifies and numifies to itself, but which boolifies to false... perhaps using "Falsify" scalar strings?

Update: Thanks tilly. Apparently my tests hadn't covered every case. They had, however, covered the case in question.

  • Comment on Re: An example of programming by contract

Replies are listed 'Best First'.
Re (tilly) 2: An example of programming by contract
by tilly (Archbishop) on Nov 26, 2001 at 01:23 UTC
    It is indeed possible to set $! in user code.

    perl -e 'print ("$_ gives ", ($!=$_), "\n") for 1..20'
    However you will note that its behaviour is highly magical and (unless you do some magic of your own) not particularly usable for any purpose other than its intended.
      Thats kind of cool....
      122 gives Disk quota exceeded 123 gives No medium found 124 gives Wrong medium type 125 gives Unknown error 125 126 gives Unknown error 126 127 gives Unknown error 127
      Think a patch to set error 125 to 'Just another Perl hacker' would be frowned upon... ;-)

      -Blake