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 – Get files and directories with the glob function
This entry was posted in Perl, Programming Languages and tagged get directories, get files, get sub-directories, glob, glob function, perl, perl glob, perl glob function. Bookmark the permalink.
Pingback: code sharing
Pingback: ebook readers
Pingback: programming