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

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.



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 a1fb5 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |