Perl opendir Function



Description

This function opens the directory EXPR, associating it with DIRHANDLE for processing, using the readdir function.

Syntax

Following is the simple syntax for this function −

 opendir DIRHANDLE, EXPR 

Return Value

This function returns true if successful.

Example

Following is the example code showing its basic usage −

 #!/usr/bin/perl -w $dirname = "/tmp"; opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n"; while( ($filename = readdir(DIR))) { print("$filename\n"); } closedir(DIR); 

When above code is executed, it produces the following result −

 . .. testdir 
perl_function_references.htm
Advertisements