> -----Original Message----- > From: JupiterHost.Net [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 02, 2004 7:15 PM > To: [EMAIL PROTECTED] > Subject: Re: using $! for die()ing with Package function > > > > > Paul Johnson wrote: > > > On Thu, Dec 02, 2004 at 05:59:49PM -0600, JupiterHost.Net wrote: > > > > > >>if I make a module, say Foobar.pm how do you make it so if a function > >>returns false you can die $!; ? > > > > > > You can't. Or at least not in the sense you want. > > > > $! is linked to the current value of errno, which will be set in the > > underlying C libraries. Its value is undefined except for just after an > > error has occurred. errno is an int (or it can be thought of as one). > > When you use $! in a numeric context you get the value of errno. When > > you use $! in a string context you get the text associated with that > > error number. > > > > It is possible to assign a numeric value to $!, after which $! in a > > string context will return the text for the error number you assigned, > > but this is rarely useful, and certainly not the general way you are > > looking for. > > > > Unfortunately perl doesn't have a standard way of coping with this other > > than using die, eval {} and $@, which might be seen as overkill in some > > situations. > > > > Take a look at $! in perldoc perlvar. > > Will do thanks for the info ;p > > I think as long as a failed open() or mkdir() (IE a system function that > does $! sets it already) then that is all I need for this project: > > sub baz { > mkdir '/dir/I/cant/make' or return; > } > > will do what i need: > > baz or die $!;
Actually mkdir returns true or false - sub baz{return mkdir '/dir/I/cant/make';} would do the same without any evaluation. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>