Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: An example of programming by contract

by premchai21 (Curate)
on Nov 25, 2001 at 22:44 UTC ( [id://127401]=note: print w/replies, xml ) Need Help??


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.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127401]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2024-03-29 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found