Chapter 7: Basic Debugging and Error Handling focuses on essential techniques in Perl to handle errors, warnings, and debugging. Mastering warn, die, and using strict and warnings will improve code reliability. Below are 30 multiple-choice questions (MCQs) to help you test your knowledge on these crucial debugging techniques.
warn function in Perl?
warn "Error occurred";die "Fatal error occurred";print "Hello World";exit;die is used in a Perl script?exit()warn()die()end()die function typically used in Perl?warn and die?warn stops execution, while die continueswarn continues execution, while die stops executionwarn and die stop executionwarn and die continue execution$! represent in Perl?perl -dperl -debugperl -Dperl debuguse Debug pragma-d flag when running the scriptdebug() function$debug variable to truecnsqbbreakstoppausex command in the Perl debugger?
p command in the Perl debugger?
s to step inton to step intop to step intor to step intobt commandbacktrace commandtrace commandst commanduse warnings; pragma do in Perl?
use strict; pragma in Perl?
strict pragma in Perl?
use strict; in a Perl script?
use warnings; is enabled?
$x = 10;my $x = 10;$x = "abc";my $x;use warnings; pragma help with in Perl?
strict in Perl?
$x = 10;my $x;$x = $y + 10;our $x = 10;use strict; and attempt to use an undeclared variable in Perl?
use strict;use warnings;use diagnostics;use debug;-w flag do when running a script?
| Qno | Answer |
|---|---|
| 1 | B) It prints a message to STDERR without terminating the program |
| 2 | B) die "Fatal error occurred"; |
| 3 | B) A warning message to STDERR |
| 4 | B) It terminates the program and prints the error message |
| 5 | C) die() |
| 6 | A) Prints an error message and stops execution |
| 7 | B) To throw exceptions and stop execution on critical errors |
| 8 | A) “Check this!” and “This will print after warning.” |
| 9 | B) warn continues execution, while die stops execution |
| 10 | A) The last error message in the program |
| 11 | A) perl -d |
| 12 | B) By using the -d flag when running the script |
| 13 | D) All of the above |
| 14 | B) It enters the Perl debugger before executing the script |
| 15 | A) c |
| 16 | A) b |
| 17 | A) Examine the contents of a variable |
| 18 | A) It prints the value of a variable |
| 19 | A) Use s to step into |
| 20 | A) Use the bt command |
| 21 | B) Enables warnings for potential issues in the code |
| 22 | B) It prevents the use of symbolic references |
| 23 | A) It prevents the creation of global variables |
| 24 | B) It enforces a stricter syntax and variable declarations |
| 25 | D) my $x; |
| 26 | B) It helps catch potential issues like undeclared variables |
| 27 | D) our $x = 10; |
| 28 | D) It will throw a compile-time error |
| 29 | B) use warnings; |
| 30 | A) It activates warnings globally |