Perl | glob() Function
glob() function in Perl is used to print the files present in a directory passed to it as an argument. This function can print all or the specific files whose extension has been passed to it.
Syntax: glob(Directory_name/File_type);
Parameter: path of the directory of which files are to be printed.
Returns: the list of files present in the given directory
Example 1: Printing names of all the files in the directory
#!/usr/bin/perl # To store the files # from the directory in the array @files = glob('C:/Users/GeeksForGeeks/Folder/*'); # Printing the created array print "@files\n"; |
Output:

Above example will print all the files of the requested directory.
Example 2: Printing names of the specific files in the directory
#!/usr/bin/perl # To store the files of a specific extension # from the directory in the array @Array = glob('C:/Users/GeeksForGeeks/Folder/*.txt'); # Printing the created array print "@Array\n"; |
Output:

Above example will print all the files of the requested directory that end with .txt extension.
Recommended Posts:
- Perl | each() Function
- Perl | abs() function
- Perl | sin() Function
- Perl | int() function
- Perl | tell() Function
- Perl | hex Function
- Perl | ord() Function
- Perl | chr() Function
- Perl | log() Function
- Perl | oct() Function
- Perl | cos() Function
- Perl | exp Function
- Perl | uc() Function
- Perl | unshift() Function
- Perl | prototype() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



