Perl (Scripting) - Store files directories in array (glob)

by
Jeremy Canfield |
Updated: March 09 2020
| Perl (Scripting) articles
The glob operator can be used to get a list of files in a directory. For example, let's say you have a Linux system with the following files.
/usr/local/file1.txt
/usr/local/file2.txt
/usr/local/file3.txt
glob can be used to store each file in an array. The nice thing about glob is that it can easily handle the wildcard character.
my @files = glob("/usr/local/file*.txt");
Likewise, glob works if you have a Windows system. This makes glob quite appealing, as this would make your Perl scripts compatible across platforms.
my @files = glob("C:\users\john\Documents\file*.txt");
Did you find this article helpful?
If so, consider buying me a coffee over at