JupiterHost.Net wrote:


Jonathan Paton wrote:

if I make a module, say Foobar.pm how do you make it so if a function
returns false you can die $!; ?



Return undef or 0, just like you are doing. Both your calls to baz have an
argument, so 1 is returned both times. I prefer undef for false.


Thanks Jonathan for the input,

Actually its not because:

 return 1 if shift;

is like doing

 my $v = shift;
 return 1 if $v;

since $v is 0 its false :)

$ cat baz.pl
#!/usr/bin/perl

use strict;
use warnings;

baz(1) or die $!;
baz(0) or die $!;

sub baz {
  return 1 if shift;
# do what here to set $! = "You are not true"; properly, safely etc... ???
  return 0;
}
$ perl baz.pl
Died at baz.pl line 7.
$

I know $! has some magic about intrenal error codes, and you just can't $! = 'reason it was false here';


I want to allow users to: baz() or die $!;

returning 0 or '' or undef will make it die() but I want to tell them why in $! if possible...

Actually I just found that if $! is set in the code it carries through:

#!/usr/bin/perl

use strict;
use warnings;

baz(1) or die $!;
baz(0) or die $!;

sub baz {
  return 1 if shift;
  open FH, 'fakepants' or return;
# do what here to set $! = "You are not true"; properly, safely etc... ???
  return 0;
}

Name "main::FH" used only once: possible typo at baz.pl line 11.
No such file or directory at baz.pl line 7.

that's cool for my needs I think, the wanring if there because of FH but that was just an example to make open set $! so its cool...

I should've thought of that before, sorry ;p

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to