Skip to Content
Programming Perl, 4th Edition
book

Programming Perl, 4th Edition

by Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
February 2012
Intermediate to advanced
1184 pages
37h 17m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 4th Edition

diagnostics

use diagnostics;            # compile–time enable
use diagnostics –verbose;

enable  diagnostics;        # runtime enable
disable diagnostics;        # runtime disable

This pragma expands the normal terse diagnostics and suppresses duplicate warnings. It augments the short versions with the more explicative and endearing descriptions found in perldiag. Like other pragmas, it also affects the compilation phase of your program, not just the run phase.

When you use diagnostics at the start of your program, this automatically enables Perl’s –w command-line switch by setting $^W to 1. The remainder of your whole compilation will then be subject to enhanced diagnostics. These still go out on STDERR.

Because of the interaction between runtime and compile-time issues, and because it’s probably not a good idea anyway, you may not use no diagnostics to turn them off at compile time. However, you may control their behavior at runtime using the disable and enable methods. (Make sure you do the use first or else you won’t be able to get at the methods.)

The –verbose flag first prints out the perldiag manpage’s introduction before any other diagnostics are issued. The $diagnostics::PRETTY variable can be set (before the use) to generate nicer escape sequences for pagers like less(1) or more(1):

BEGIN { $diagnostics::PRETTY = 1 }
use diagnostics;

Warnings dispatched from Perl and detected by this pragma are each displayed only once. This is useful when you’re caught in a loop that’s generating the same warning (like ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 3rd Edition

Programming Perl, 3rd Edition

Larry Wall, Tom Christiansen, Jon Orwant
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Learning Perl, 8th Edition

Learning Perl, 8th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9781449321451Supplemental ContentErrata Page