in reply to Re: 255: perl compilation error code and ssh cannot connect code
in thread 255: perl compilation error code and ssh cannot connect code
Hi,
Testing this shows that it appears to work, even for compile-time* errors:
$ cat ex.pl #!/usr/bin/env perl use warnings; use strict; END { $? = 250 if $? == 255 } print $c; $ perl ex.pl ; echo $? Global symbol "$c" requires explicit package name (did you forget to d +eclare "my $c"?) at ex.pl line 7. Execution of ex.pl aborted due to compilation errors. 250
Note this is documented in $?. However, this solution means you'd have to insert the END block at the top of every script that you run like this, so personally I like Corion's suggestion of a wrapper script better. Also, consider what kind of errors you are catching. Syntax errors are something that you can catch when you're developing the script, so I don't see how those could sneak in. Runtime errors, like you mention in the bug report accessing something that doesn't exist, are something you could catch and handle gracefully within the script, for example there's Try::Tiny.
* Update: Actually I think this may be inaccurate, although it seems to catch many syntax errors and such, there might be cases where the END block isn't executed; if I get around to it I'll test more later.
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: 255: perl compilation error code and ssh cannot connect code (updated)
by i5513 (Pilgrim) on Nov 02, 2016 at 11:30 UTC | |
by haukex (Archbishop) on Nov 02, 2016 at 13:42 UTC | |
|
Re^3: 255: perl compilation error code and ssh cannot connect code
by i5513 (Pilgrim) on Nov 02, 2016 at 08:20 UTC |