Jump to content

Perl Programming/Keywords/-z

From Wikibooks, open books for an open world
Previous: -x Keywords Next: __DATA__

The -z keyword

[edit | edit source]

-z is a file test that returns true, if the file has zero size (is empty).

It takes one argument, either a FILENAME, a FILEHANDLE, or a DIRHANDLE to test the associated file to see if the file has zero size. If the argument is omitted, it tests $_. -z returns 1 for true and an empty string for false. If the file doesn't exist or can't be examined, it returns undef and sets $! (errno).

Syntax

[edit | edit source]
  -z FILENAME
  -z FILEHANDLE
  -z EXPRESSION
  -z DIRHANDLE
  -z
Previous: -x Keywords Next: __DATA__