How to make perl exit with an error code upon use of uninitialized-value?
I don't see how to make perl fail upon use of uninitialized-value. Is there a way to make this the default behavior? Thanks.
https://perlmaven.com/use-of-uninitialized-value
perl
add a comment |
I don't see how to make perl fail upon use of uninitialized-value. Is there a way to make this the default behavior? Thanks.
https://perlmaven.com/use-of-uninitialized-value
perl
2
What have you tried so far? You didn't include any code, so it's impossible to know. Also, take a look atexit
.
– Matt Jacob
Nov 22 '18 at 3:51
I don’t know what to try. I want the program to fail instead of just giving a warning. This must be done with some kind of configuration of Perl at the beginning of a script. Exit won’t work.
– user1424739
Nov 22 '18 at 4:04
1
Please edit your question and include the code you're claiming isn't working.
– Matt Jacob
Nov 22 '18 at 4:05
6
perldoc.perl.org/warnings.html#Fatal-Warnings
– Shawn
Nov 22 '18 at 4:14
The link from @Shawn seems to be what you want. But also see Carp::Always
– zdim
Nov 22 '18 at 6:10
add a comment |
I don't see how to make perl fail upon use of uninitialized-value. Is there a way to make this the default behavior? Thanks.
https://perlmaven.com/use-of-uninitialized-value
perl
I don't see how to make perl fail upon use of uninitialized-value. Is there a way to make this the default behavior? Thanks.
https://perlmaven.com/use-of-uninitialized-value
perl
perl
asked Nov 22 '18 at 3:39
user1424739user1424739
1,26931731
1,26931731
2
What have you tried so far? You didn't include any code, so it's impossible to know. Also, take a look atexit
.
– Matt Jacob
Nov 22 '18 at 3:51
I don’t know what to try. I want the program to fail instead of just giving a warning. This must be done with some kind of configuration of Perl at the beginning of a script. Exit won’t work.
– user1424739
Nov 22 '18 at 4:04
1
Please edit your question and include the code you're claiming isn't working.
– Matt Jacob
Nov 22 '18 at 4:05
6
perldoc.perl.org/warnings.html#Fatal-Warnings
– Shawn
Nov 22 '18 at 4:14
The link from @Shawn seems to be what you want. But also see Carp::Always
– zdim
Nov 22 '18 at 6:10
add a comment |
2
What have you tried so far? You didn't include any code, so it's impossible to know. Also, take a look atexit
.
– Matt Jacob
Nov 22 '18 at 3:51
I don’t know what to try. I want the program to fail instead of just giving a warning. This must be done with some kind of configuration of Perl at the beginning of a script. Exit won’t work.
– user1424739
Nov 22 '18 at 4:04
1
Please edit your question and include the code you're claiming isn't working.
– Matt Jacob
Nov 22 '18 at 4:05
6
perldoc.perl.org/warnings.html#Fatal-Warnings
– Shawn
Nov 22 '18 at 4:14
The link from @Shawn seems to be what you want. But also see Carp::Always
– zdim
Nov 22 '18 at 6:10
2
2
What have you tried so far? You didn't include any code, so it's impossible to know. Also, take a look at
exit
.– Matt Jacob
Nov 22 '18 at 3:51
What have you tried so far? You didn't include any code, so it's impossible to know. Also, take a look at
exit
.– Matt Jacob
Nov 22 '18 at 3:51
I don’t know what to try. I want the program to fail instead of just giving a warning. This must be done with some kind of configuration of Perl at the beginning of a script. Exit won’t work.
– user1424739
Nov 22 '18 at 4:04
I don’t know what to try. I want the program to fail instead of just giving a warning. This must be done with some kind of configuration of Perl at the beginning of a script. Exit won’t work.
– user1424739
Nov 22 '18 at 4:04
1
1
Please edit your question and include the code you're claiming isn't working.
– Matt Jacob
Nov 22 '18 at 4:05
Please edit your question and include the code you're claiming isn't working.
– Matt Jacob
Nov 22 '18 at 4:05
6
6
perldoc.perl.org/warnings.html#Fatal-Warnings
– Shawn
Nov 22 '18 at 4:14
perldoc.perl.org/warnings.html#Fatal-Warnings
– Shawn
Nov 22 '18 at 4:14
The link from @Shawn seems to be what you want. But also see Carp::Always
– zdim
Nov 22 '18 at 6:10
The link from @Shawn seems to be what you want. But also see Carp::Always
– zdim
Nov 22 '18 at 6:10
add a comment |
2 Answers
2
active
oldest
votes
Something like this perhaps:
#!/usr/bin/perl
use strict;
use warnings;
use warnings FATAL => qw[uninitialized];
use feature 'say';
my $foo;
say "Foo is $foo";
say "Don't get here";
Comment out the FATAL
line to see the standard behaviour.
add a comment |
Dave's answer sure is the best pick for the described use case.
Here is another solution, that demonstrates the use of the warning signal handler (see http://perldoc.perl.org/functions/warn.html).
The benefit of using a signal handler is flexibility : you can trap any kind of warning, analyze it and then implement any behavior you like. In the given use case this is an overkill, it but can be useful in more complex cases.
use strict;
use warnings;
use feature "say";
local $SIG{__WARN__} = sub {
if ($_[0] =~ /^Use of uninitialized value/) {
die $_[0];
} else {
warn $_[0] ;
}
};
my $foo;
say "Foo is $foo";
say "Dont get here";
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423543%2fhow-to-make-perl-exit-with-an-error-code-upon-use-of-uninitialized-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Something like this perhaps:
#!/usr/bin/perl
use strict;
use warnings;
use warnings FATAL => qw[uninitialized];
use feature 'say';
my $foo;
say "Foo is $foo";
say "Don't get here";
Comment out the FATAL
line to see the standard behaviour.
add a comment |
Something like this perhaps:
#!/usr/bin/perl
use strict;
use warnings;
use warnings FATAL => qw[uninitialized];
use feature 'say';
my $foo;
say "Foo is $foo";
say "Don't get here";
Comment out the FATAL
line to see the standard behaviour.
add a comment |
Something like this perhaps:
#!/usr/bin/perl
use strict;
use warnings;
use warnings FATAL => qw[uninitialized];
use feature 'say';
my $foo;
say "Foo is $foo";
say "Don't get here";
Comment out the FATAL
line to see the standard behaviour.
Something like this perhaps:
#!/usr/bin/perl
use strict;
use warnings;
use warnings FATAL => qw[uninitialized];
use feature 'say';
my $foo;
say "Foo is $foo";
say "Don't get here";
Comment out the FATAL
line to see the standard behaviour.
answered Nov 22 '18 at 9:34
Dave CrossDave Cross
48.5k34079
48.5k34079
add a comment |
add a comment |
Dave's answer sure is the best pick for the described use case.
Here is another solution, that demonstrates the use of the warning signal handler (see http://perldoc.perl.org/functions/warn.html).
The benefit of using a signal handler is flexibility : you can trap any kind of warning, analyze it and then implement any behavior you like. In the given use case this is an overkill, it but can be useful in more complex cases.
use strict;
use warnings;
use feature "say";
local $SIG{__WARN__} = sub {
if ($_[0] =~ /^Use of uninitialized value/) {
die $_[0];
} else {
warn $_[0] ;
}
};
my $foo;
say "Foo is $foo";
say "Dont get here";
add a comment |
Dave's answer sure is the best pick for the described use case.
Here is another solution, that demonstrates the use of the warning signal handler (see http://perldoc.perl.org/functions/warn.html).
The benefit of using a signal handler is flexibility : you can trap any kind of warning, analyze it and then implement any behavior you like. In the given use case this is an overkill, it but can be useful in more complex cases.
use strict;
use warnings;
use feature "say";
local $SIG{__WARN__} = sub {
if ($_[0] =~ /^Use of uninitialized value/) {
die $_[0];
} else {
warn $_[0] ;
}
};
my $foo;
say "Foo is $foo";
say "Dont get here";
add a comment |
Dave's answer sure is the best pick for the described use case.
Here is another solution, that demonstrates the use of the warning signal handler (see http://perldoc.perl.org/functions/warn.html).
The benefit of using a signal handler is flexibility : you can trap any kind of warning, analyze it and then implement any behavior you like. In the given use case this is an overkill, it but can be useful in more complex cases.
use strict;
use warnings;
use feature "say";
local $SIG{__WARN__} = sub {
if ($_[0] =~ /^Use of uninitialized value/) {
die $_[0];
} else {
warn $_[0] ;
}
};
my $foo;
say "Foo is $foo";
say "Dont get here";
Dave's answer sure is the best pick for the described use case.
Here is another solution, that demonstrates the use of the warning signal handler (see http://perldoc.perl.org/functions/warn.html).
The benefit of using a signal handler is flexibility : you can trap any kind of warning, analyze it and then implement any behavior you like. In the given use case this is an overkill, it but can be useful in more complex cases.
use strict;
use warnings;
use feature "say";
local $SIG{__WARN__} = sub {
if ($_[0] =~ /^Use of uninitialized value/) {
die $_[0];
} else {
warn $_[0] ;
}
};
my $foo;
say "Foo is $foo";
say "Dont get here";
answered Nov 22 '18 at 20:57
GMBGMB
20.6k41028
20.6k41028
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423543%2fhow-to-make-perl-exit-with-an-error-code-upon-use-of-uninitialized-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
What have you tried so far? You didn't include any code, so it's impossible to know. Also, take a look at
exit
.– Matt Jacob
Nov 22 '18 at 3:51
I don’t know what to try. I want the program to fail instead of just giving a warning. This must be done with some kind of configuration of Perl at the beginning of a script. Exit won’t work.
– user1424739
Nov 22 '18 at 4:04
1
Please edit your question and include the code you're claiming isn't working.
– Matt Jacob
Nov 22 '18 at 4:05
6
perldoc.perl.org/warnings.html#Fatal-Warnings
– Shawn
Nov 22 '18 at 4:14
The link from @Shawn seems to be what you want. But also see Carp::Always
– zdim
Nov 22 '18 at 6:10