Answer 2.1: Although the exact warning message differs between versions of Perl, each of the programs should output a warning. To turn these into a full program, insert the given lines into a short program such as this one then run the program to see the warning:
#!/usr/bin/perl use warnings; print;
Program 1 uses the
Use of uninitialized value in print at test line 3.
Program 2 adds two numbers, but doesn’t do anything with the result. That’s a pretty silly thing. Why do the work if you don’t use the result for anything?
Useless use of a constant in void context at test line 3.
Program 3 adds a number to a variable that has no value then prints
the result. The warning message complains about the uninitialized value in
the addition. You should also get the result of the
1 after the warning:
Use of uninitialized value in addition (+) at test line 3. 1
2.2: You can use the same program you created for the Answer to Exercise 2.1.
Program 1 complained about an uninitialized value. With
on, you get the same warning, but also the entry from the perldiag for that warning. The longer warning tries to explain what you might have done to cause the warning. The entry may not always talk about your ...