Re: My own die message
Chris == Chris Devers [EMAIL PROTECTED] writes: Chris On Thu, 31 Mar 2005, Ankur Gupta wrote: No I do not [want to] die so fast.. I want to do some processing based on the died message. Chris Fine then. Chris eval { Chris risky_action(); Chris } You forgot a semicolon here, which will make Perl start to think you mean this to be an if modifier instead of a separate if statement. Wh! Chris if $@ { Chris my $status = $@; Chris my $result = do_some_processing(); Chris die Got $status, did some processing: $result\n; Chris } Chris This should work. Yes, it *should*, and doesn't. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: My own die message
On Thu, 31 Mar 2005, Randal L. Schwartz wrote: Chris == Chris Devers [EMAIL PROTECTED] writes: Chris Fine then. Chris eval { Chris risky_action(); Chris } You forgot a semicolon here, which will make Perl start to think you mean this to be an if modifier instead of a separate if statement. Wh! Whoops! Today's lesson: test early, test often, and always always always test before making off the cuff suggestions on a mailing list. :-) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
My own die message
Hi, I have the following code : eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah I want $@ to contain unable to find file. What am I doing wrong or it is not possible to override [EMAIL PROTECTED] Thanks, Ankur
Re: My own die message
On 03/30/2005 01:48 PM, Ankur Gupta wrote: eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah If you actually want to die, try moving the die outside of the eval: eval { require file;} or die unable to find file $@; -- Todd de Gruyl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: My own die message
No I do not wanna die so fast.. I want to do some processing based on the died message. -- Ankur -Original Message- From: Todd de Gruyl [mailto:[EMAIL PROTECTED] Sent: Thursday, March 31, 2005 12:24 AM To: Ankur Gupta Cc: beginners@perl.org Subject: Re: My own die message On 03/30/2005 01:48 PM, Ankur Gupta wrote: eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah If you actually want to die, try moving the die outside of the eval: eval { require file;} or die unable to find file $@; -- Todd de Gruyl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: My own die message
On Thu, 31 Mar 2005, Ankur Gupta wrote: No I do not [want to] die so fast.. I want to do some processing based on the died message. Fine then. eval { risky_action(); } if $@ { my $status = $@; my $result = do_some_processing(); die Got $status, did some processing: $result\n; } This should work. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: My own die message
On Thu, 31 Mar 2005 00:18:14 +0530, Ankur Gupta wrote: Hi, I have the following code : eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah I want $@ to contain unable to find file. What am I doing wrong or it is not possible to override [EMAIL PROTECTED] Thanks, Ankur Hi Ankur, Other people gave you good answers, I just wanted to claify to you why your code didn't act as you expected. Basically, you have the right idea - a die inside an eval will return its argument in the $@ variable. The problem in your code is, your die never gets executed! The require, when it fails, dies itself, with its own error message - it doesn't return false, so your die never gets a chance to execute. The solution, as other people have said, is simply to handle the string outside the eval. Simply put: eval {require file}; print Unable to find file!\n if $@; See perldoc perlvar for details about $@, perldoc -f eval for more info about eval and perldoc -f require for more require info. Hope this helps, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: My own die message
-Original Message- From: Offer Kaye [mailto:[EMAIL PROTECTED] Sent: Thursday, March 31, 2005 2:21 AM To: Ankur Gupta; Perl Beginners Subject: Re: My own die message On Thu, 31 Mar 2005 00:18:14 +0530, Ankur Gupta wrote: Hi, I have the following code : eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah I want $@ to contain unable to find file. What am I doing wrong or it is not possible to override [EMAIL PROTECTED] Thanks, Ankur Hi Ankur, Other people gave you good answers, I just wanted to claify to you why your code didn't act as you expected. Basically, you have the right idea - a die inside an eval will return its argument in the $@ variable. The problem in your code is, your die never gets executed! The require, when it fails, dies itself, with its own error message - it doesn't return false, so your die never gets a chance to execute. The solution, as other people have said, is simply to handle the string outside the eval. Simply put: eval {require file}; print Unable to find file!\n if $@; See perldoc perlvar for details about $@, perldoc -f eval for more info about eval and perldoc -f require for more require info. Hope this helps, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response Thanks Kaye and all, This helps... -- Ankur -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: My own die message
On 30/03/2005, Ankur Gupta wrote: I have the following code : eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah I want $@ to contain unable to find file. What am I doing wrong or it is not possible to override [EMAIL PROTECTED] The require fails before you die. You will need something like this: eval { require file; } print Your message if $@ $@ =~ m/^Can't locate file/; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response