![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 17
Rep Power: 0
![]() |
Perl Error Handling
Hello everyone...
I'm writing a program in Perl. I am trying to handle errors using the warn function. Problem is... I want it to do more than one thing in the event of an error... During a warn I need it to execute a block of code. Everything I try { } and ( ) doesn't seem to work. $sock or warn ("print something"); Needs to be something like: $sock or { warn ("print something"); logfunction (logError); } I keep getting errors doing it this way. Any suggestions? Thanks. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
if block?
assuming $sock is boolean if (!$sock) {
warn ("print something");
logfunction (logError);
}
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
if you are trying to use the warn in the case of a function call failure ... then something like this might work for you
function() || warn('error message') && warnFunction();as illustrated here: #!/usr/bin/perl -w
use strict;
sub doSomething() {
return(0);
}
sub warnFunction() {
print "Warn Function\n";
}
doSomething() || warn('called warn()',"\n") && warnFunction();otherwise ... if you are just trying to test the value of a variable ... then use an 'if' as stated above.
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ]; /* Don't make me use it! */ |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Aug 2005
Posts: 17
Rep Power: 0
![]() |
Thanks for your help. I had if !($sock) instead of if (!$sock)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|