about readdir call

[email protected] ("Rajnikant")
Newsgroups perl.beginners
Message-ID <[email protected]>
Hello everyone,
 
I'm reading one directory using readdir call. but I'm getting different
output from that I got by 
running ls -l command on same directory manually. Following is the snippet
I'm using:
 
#!/usr/bin/perl -w
$dirname = "/test_dir";
opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n";
while( ($filename = readdir(DIR))){
     print("$filename\n");
}
closedir(DIR);
 
From above snippet I got following output:
.
..
2.OUTPUT
4.OUTPUT
1.OUTPUT
3.OUTPUT
5.OUTPUT

test_dir contains :
test_dir# ls -l
-rw-r--r-- 1 root root 72400 Jun  5 22:35 1.OUTPUT
-rw-r--r-- 1 root root 69785 Jun  5 22:33 2.OUTPUT
-rw-r--r-- 1 root root 69960 Jun  5 22:33 3.OUTPUT
-rw-r--r-- 1 root root 69785 Jun  5 22:33 4.OUTPUT
-rw-r--r-- 1 root root 69785 Jun  5 22:33 5.OUTPUT
This is what I was expecting from readdir call.
 
Order of files got disturbed.
 
Do anyone know reason why I'm getting such output? 
What are the modifications if I want output same to that of 'ls -l'?
Thanks in advance.
 
 
 
 
~~~~~~~~~~~~~~~~~~~~
Thanks and Best regards,
~ Rajnikant
Software Engg.
Persistent Sys. Ltd.
Ph. +91 98222 04088
 

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.