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!
Blog Archives
Search Blog Archives
Pingback: code sharing
Pingback: ebook readers
Pingback: programming