Copyright © tutorialspoint.com

PERL opendir Function


Syntax

opendir DIRHANDLE, EXPR


Definition and Usage

Opens the directory EXPR, associating it with DIRHANDLE for processing, using the readdir function

Return Value

  • 0 on failure

  • 0 on failure

Example

Try out following example:

#!/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);

It will produce following results:

.
..
testdir

Copyright © tutorialspoint.com