|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
modify $!
Ok, I've done a bit of experementation, with no sucess... Is there a way to set $! to a string to send an error back?
I'm writing a small library so to speak... and I want people to be able to use things like this $var = mysub($othervar) || die($!) Is it possible at all? |
|
#2
|
|||
|
|||
|
perlvar says:
If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding system error string. You can assign to $! to set errno if, for instance, you want "$!" to return the string for error n, or you want to set the exit value for the die() operator.
__________________
- dsb - ![]() Perl Guy |
|
#3
|
|||
|
|||
|
I had found that...
I had already read that... but I couldn't make any sense of it... and I still can't...
|
|
#4
|
||||
|
||||
|
I don't really get what you're asking. Why not just do this?
Code:
my $var = mysub($othervar) or die('Couldn\'t get var: '.$!);
I use this everywhere and it works beautifully for me. |
|
#5
|
|||
|
|||
|
Ok
Ok... mabey an example of what I tried will make it obvious...
sub mysub { if(!shift){ my ($package, $file, $line) = caller; $! = "Error on line $line of $package in $file: Failed to pass true value"; return; }else{ return "That was true!"; } } sub dienice { print shift; exit; } Now, of course thats a worthless sub, but I want to be able to SET $! like that... so that if someone did this: $myvar = mysub(0) || dienice($!); It would spit out something resembling this: Error on line 4 of somepackage in myfile.pl: Failed to pass true value Note: All code there was thrown together and probably would NOT execute properly... I hope that helped explain my goal... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > modify $! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|