Jim Gibson <jimsgib...@gmail.com> writes: > If you want to process files in a certain order, then save the files in an > array. When find is finished, sort that array and process the files in any > order. For example, if you want to process files in chronological order, in > the wanted routine save the file path and age as an array entry (untested): > > my @files; > my $dir = '/some/directory/path'; > > find( sub{ > my $age = -M $File::Find::name; > push( @files, [ $File::Find::name, $age ] ); > }, $dir); > > for my $entry ( sort { $a->[1] <=> $b[1] } @files ) { > my($file,$age) = @$entry; > # process file > } > > (reverse $a and $b if you want the reverse order).
I see the final result but am slightly mystified by some of the notation. First off the formulation of the find() function. I've seen it before but don't really understand it. Seems like the guts of find() are missing, but I know they are not. I guess it could be expressed: find( sub{..results of this sub routine},$dir); Like you might do with `find($var1,$var2);' But there you would expect to see `find()' have some lines of processing to the two elems of @_ passed in. In your formulation it appears sub processes itself, and somehow `find()' knows to do this to each file in $dir I'm sure its all good perl but it just looks confusing to me. ------- --------- ---=--- --------- -------- What are the brackets ([]) doing here: push( @files, [ $File::Find::name, $age ] ); and what is this creature: my($file,$age) = @$entry; ^^ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/