SPUG: die from BEGIN; how suppress ugly message?

Charles DeRykus ced at carios2.ca.boeing.com
Thu Jan 27 14:15:50 CST 2000



> 
> 
> BEGIN { eval { print "foo\n"; die "bar" }; }
> 
>> Been there, tried that (before posting)

>> As I said, if you have -n/-p turned on, you can't test
>> $@ to decide what to do about the trapped exception
>> until after you get a line of input!

>> And you *really need* BEGIN when using -n/-p, otherwise
>> everything is in the implicit input-reading loop!

>> Hence my desire for another solution to suppressing
>> errors within BEGIN, and I'm happy with the
>> redirection to /dev/null idea.


I believe I understand your problem now. 

This is probably more convoluted than anyone will 
want to suffer reading through but I believe there's
another possibility:

You can stack BEGIN blocks so you can conceivably get 
the eval error before you ever see a line of input.
The only catch is that the global $@ doesn't remain set 
across BEGIN blocks so you have to use a package variable:  

perl -ne ' 
BEGIN { eval { ... ; die "bar"; ... }; $e= $@ }   
BEGIN { print $e }
...
END


Of course, you can just toss STDERR  too but the
above allows you to actually see $@ before -n/-p
reads a line.

--
Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list