Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the File-Next CPAN distribution.

Report information
The Basics
Id: 28942
Status: resolved
Priority: 0/
Queue: File-Next

People
Owner: Nobody in particular
Requestors: robin-bitcard [...] robinbowes.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.00
Fixed in: (no value)



Subject: Custom sort routine
Hi, I'm trying to use a custom sort routine with File::Next. The example on the cpan page suggests something like this: sort_files => sub { $a->[1] cmp $b->[1] } However, that doesn't work - $a and $b are not defined. Looking at the code in Next.pm, you use this for sort_standard: return $_[0]->[1] cmp $_[1]->[1] Now, I want to sort by file size, so I've written a routine like this: sub sort_by_size($$) { my $sizea = -f $_[0]->[2] ? -s $_[0]->[2] : 0; my $sizeb = -f $_[1]->[2] ? -s $_[1]->[2] : 0; $sizea <=> $sizeb; } and I use it like this: my $files = File::Next::files( { sort_files => \&sort_by_size, }, $srcdir ); Does that look OK? One question: why do you use subroutine prototypes? Why not just pass the array to the sort routine explicitly by reference ? Thanks, R.
The prototypes aren't real prototypes. There's magic in having the prototypes on a custom sort routine. Please don't reply to this ticket. If you have problems, please add a ticket to http://code.google.com/p/file-next/issues/list.