O'Reilly logo

Computer Science & Perl Programming by Jon Orwant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. What Is Truth?

Nathan Torkington

Some programming languages give you a single TRUE and a single FALSE. Others make us represent each with integers (typically 1 and 0). But not Perl. Truth plays a larger role in Perl than most other languages, and its subtleties often confuse beginners.

In Perl, truthfulness is determined from a few simple rules. To understand one of those rules, though, we need to first learn about good programming practice, warnings, laziness, and undef. Then we can learn the nature of truth and see how to apply it in our own programs.

The undef Function

Perl was designed for system administrators who want to automate the automatable tasks of their jobs. Such people typically produce small programs, and don’t need to worry about formally verifiable correctness, corporate coding standards, and other such things. They just want to get the job done.

For this reason, Perl’s default behavior allows the programmer to be lazy and leave off parentheses around function arguments, use subroutines before they’re defined, and use variables without initializations or even definitions.

However, the same practices that enable small programs to be written quickly can bog down larger programs by permitting subtle errors. Because Perl assumes that the programmer is all-knowing and perfect, it fails to notice things that smart and lazy programmers do deliberately but are mistakes for the rest of us. That’s what Perl’s -w flag is for.

The -w flag turns on warnings for ambiguous ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required