- Sample Program to Read Directories

This section provides a tutorial example on how to open the current directory using opendir() function and read its file names using readdir() function.

The following sample program,, opens the current directory twice. The first time, it reads the directory one entry at a time. The second time, it reads all entries of the directory to an array.

#- Copyright (c) All Rights Reserved.
   print "Reading one entry at a time...\n";
   while ($f=readdir(DIR)) {
      print "$f\n";
   print "\n";
   print "Reading all entries into an array...\n";
   @a = readdir(DIR);
   for (@a) {
      print "$_\n";

Now run this program by entering the program file name directly in a command window, and you will get the following output:

Reading one entry at a time...

Reading all entries into an array...

Note that:

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

Open Directories and Read File Names

 opendir() - Open Directory to Read File Names - Sample Program to Read Directories - Displaying the Directory Tree - Searching Text in Directory Files

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS


 Full Version in PDF/EPUB