FreeKB - Store files directories in an array in Perl (glob)
Store files directories in an array in Perl (glob)

Home > Search


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");

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 6ebd3 in the box below so that we can be sure you are a human.




Comments