Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL readdir Function



Syntax

readdir DIRHANDLE


Definition and Usage

In a scalar context, returns the next directory entry from the directory associated with DIRHANDLE. In a list context, returns all of the remaining directory entries in DIRHANDLE.

Return Value

  • Return Value in Scalar Context: The name of the next file in the directory connected to DIRHANDLE.

  • Return Value in Array Context: A list containing all of the files in the directory connected to DIRHANDLE.

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


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names