| 1. |
What are directories in Perl and how to access it using Perl? |
|
Answer» We all use different operating systems for our day-to-day tasks. Each of these operating systems COME with their own set of COMMANDS to look at the FILES list within a directory. For example, all Linux users use the 'li' command, whereas all Windows users use the 'DIR' command to explore the list of directories and sub-directories in their respective OS. Perl PROVIDES a universal way of accessing directories in Perl using Perl directory functions. Directory handling in Perl is similar to file handling. Here is a code snippet showing how to access a directory: my $directory1 = '/users/karlosray'; opendir (DIR, $directory1) or die "Unable to open the directory, $!"; while ($file = readdir DIR) { print "$file \n"; } closedir DIR;In this case the file does not exist and hence showed this output. |
|