Directories and Paths

Learn how to deal with directories and paths in Perl.

Manipulating directories

Working with directories is similar to working with files, except that we can’t write to directories.

Open a directory

Open a directory handle with the opendir built-in:

opendir my $dirh, '/home/monkeytamer/tasks/';

Read from a directory

The readdir built-in reads from a directory. As with readline, you may iterate over the contents of directories one entry at a time or you may assign everything to an array in one swoop:

Access this course and 1400+ top-rated courses and projects.