List the files and subdirectories in a directory in alphabetical order. : closedir « File « Perl






List the files and subdirectories in a directory in alphabetical order.

    
#!/usr/local/bin/perl 

opendir(HOMEDIR, "/u/jqpublic") || die ("Unable to open directory"); 
@files = readdir(HOMEDIR); 
closedir(HOMEDIR); 
foreach $file (sort @files) { 
    print ("$file\n"); 
} 

   
    
    
    
  








Related examples in the same category

1.When you're done with a directory, you need to close it with the closedir command:
2.The closedir function closes the directory that was opened by the opendir function.