Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Amit Saxena
Hi all, The following perl program, for sorting files in a directory, without using any OS specific command, ordered by modified timestamp is not working. Please help. *Perl Program* #!perl.exe use strict; use warnings; my $directory_name; print "This program print the files in asce

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Shawn H Corey
On 10-12-01 07:19 AM, Amit Saxena wrote: print "Sorted listing of files in<$directory_name> directory are as follows :-\n"; my $j; foreach $j ( @files_in_directory ) foreach $j ( @sorted_files_in_directory ) { print $j . "\n"; } print "\n"; -- Just my 0.0002 million dollars w

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread John W. Krahn
Amit Saxena wrote: Hi all, Hello, The following perl program, for sorting files in a directory, without using any OS specific command, ordered by modified timestamp is not working. Please help. *Perl Program* #!perl.exe use strict; use warnings; my $directory_name; print "This pr

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread John W. Krahn
John W. Krahn wrote: Amit Saxena wrote: my @sorted_files_in_directory; @sorted_files_in_directory = sort { (stat($a))[9]<=> (stat($b))[9] } If you read the documentation for readdir you will see where it says: If you're planning to filetest the return values out of a "readdir", you'd better

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Shawn H Corey
On 10-12-01 09:57 AM, John W. Krahn wrote: Or just: print map( "$_\n", @files_in_directory ), "\n"; print map( "$_\n", @sorted_files_in_directory ), "\n"; -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding.

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Shlomi Fish
On Wednesday 01 December 2010 16:57:07 John W. Krahn wrote: > Amit Saxena wrote: > > Hi all, > > { > > > > next if ( ( $filename eq "." ) or ( $filename eq ".." ) ); > > > > push ( @files_in_directory, $filename ); > > > > } > > Since all you are doing is populating t

Re: Sorting files in a directory, without using any OS specific command, ordered by modified timestamp

2010-12-01 Thread Mark
> On Dec 1, 7:31 am, jwkr...@shaw.ca ("John W. Krahn") wrote: > > Correction: > > my @sorted_files_in_directory = >      map $_->[ 1 ], >      sort { $a->[ 0 ] <=> $b->[ 0 ] } >      map { ( stat "$directory_name/$_" )[ 9 ], $_ } map { [ ( stat "$directory_name/$_" )[ 9 ], $_ ] } >