Perl – Get files and directories with the glob function

Recently, as part of a larger Perl application, I had to get all the files and sub-directories of the working directory. Using the built-in ‘glob’ function, I was able to quickly implement a subroutine to do this and also differentiate a file from a directory. In a list context, as demonstrated below, the ‘glob’ function returns a list of file/directory names that match the pattern. I then loop through this list and differentiate a file from a directory and store it in its respective array. Pretty quick and simple!

Perl subroutine to retrieve all files and sub-directories of working directory

Perl subroutine to retrieve all files and sub-directories of working directory

This entry was posted in Perl, Programming Languages and tagged , , , , , , , . Bookmark the permalink.

3 Responses to Perl – Get files and directories with the glob function

  1. Pingback: code sharing

  2. Pingback: ebook readers

  3. Pingback: programming

Leave a Reply

Your email address will not be published. Required fields are marked *


3 + two =