> -----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>