Comparer-file_size
view release on metacpan or search on metacpan
my $cmp = Comparer::file_size::gen_comparer();
my @sorted = sort { $cmp->($a,$b) } "small", "biggest", "big";
# => ("small", "big", "biggest")
DESCRIPTION
This comparer assumes the entries are filenames and will compare their
size.
COMPARER ARGUMENTS
follow_symlink
Bool, default true. If set to false, will use lstat() function instead
of the default stat().
reverse
Bool.
HOMEPAGE
Please visit the project's homepage at
<https://metacpan.org/release/Comparer-file_size>.
SOURCE
Source repository is at
lib/Comparer/file_size.pm view on Meta::CPAN
};
}
sub gen_comparer {
my %args = @_;
my $follow_symlink = $args{follow_symlink} // 1;
my $reverse = $args{reverse};
sub {
my @st1 = $follow_symlink ? stat($_[0]) : lstat($_[0]);
my @st2 = $follow_symlink ? stat($_[1]) : lstat($_[1]);
(
$st1[7] <=> $st2[7]
) * ($reverse ? -1 : 1)
};
}
1;
# ABSTRACT: Compare file's size
lib/Comparer/file_size.pm view on Meta::CPAN
This comparer assumes the entries are filenames and will compare their
size.
=for Pod::Coverage ^(meta|gen_comparer)$
=head1 COMPARER ARGUMENTS
=head2 follow_symlink
Bool, default true. If set to false, will use C<lstat()> function instead of the
default C<stat()>.
=head2 reverse
Bool.
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/Comparer-file_size>.
=head1 SOURCE
( run in 0.929 second using v1.01-cache-2.11-cpan-49f99fa48dc )