Skip to content

Commit 62925f5

Browse files
authored
ls: list file arguments in columns
* Test case: "perl ls spell ar ar ." * The argument list is split into files and directories * File arguments are listed first in multi-column output, followed by each directory argument * Previously List() was called once per file argument; this was incorrect because List() is unable to format the arguments together in columns * Fix this by preparing a sorted file list and attribute hash (containing stat() data), then calling List() once * DirEntries() has to be called once per file, then the stat data returned is merged into a single hash * Bump version
1 parent f2d8543 commit 62925f5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

bin/ls

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ my $Now = time; # time we were invoked
114114
my %Options = (); # option/flag arguments
115115
my $SixMonths = # long listing time if < 6 months, else year
116116
60*60*24*(365/2);
117-
our $VERSION = '0.70'; # because we're V7-compatible :)
117+
our $VERSION = '0.71';
118118
my $WinCols; # window columns of output
119119

120120
# ------ compensate for lack of getpwuid/getgrgid on some platforms
@@ -517,10 +517,15 @@ if ($#ARGV < 0) {
517517
for my $Arg (@Files) {
518518
$Attributes{$Arg} = stat($Arg);
519519
}
520-
for my $Arg (Order(\%Options, \%Attributes, @Files)) {
520+
if (@Files) {
521521
$First = 0;
522-
List($Arg, \%Options, 0, 0,
523-
DirEntries(\%Options, $Arg));
522+
my %attrs;
523+
foreach (@Files) {
524+
my @ret = DirEntries(\%Options, $_);
525+
%attrs = (%attrs, %{ $ret[-1] });
526+
}
527+
my @sorted = Order(\%Options, \%Attributes, @Files);
528+
List('.', \%Options, 0, 0, @sorted, \%attrs);
524529
}
525530
for my $Arg (@Dirs) {
526531
$Attributes{$Arg} = stat($Arg);

0 commit comments

Comments
 (0)