Perl closedir Function


Advertisements


Description

This function closes the directory handle DIRHANDLE.

Syntax

Following is the simple syntax for this function −

closedir DIRHANDLE

Return Value

This function returns 0 on failure and 1 on success.

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


Advertisements