Thread Ausgabe von Fileliste in Spalten (6 answers)
Opened by harvey at 2007-10-06 15:36

harvey
 2007-10-06 19:10
#100412 #100412
User since
2007-10-06
16 Artikel
BenutzerIn
[default_avatar]
ptk+2007-10-06 16:24:56--
Ach so. Ein Modul ist mir nicht bekannt. Man könnte es so lösen
Code: (dl )
1
2
perl -Mstrict -MList::Util=max -e 'my @a=@ARGV;my $max=max map { length } @a; my $col = 0; while(my $a = shift @a) { $col+=(1+$max); if ($col >= 80) { $col = (1+$max); print "\n" } print $a." "x(1+$max-length($a))} print "\n"' ..
.


Prima. So geht's. :)

Jetzt brauche ich nur noch eine Systemvariable, die mir sagt, wie breit mein Terminal gerade ist (KDE-konsole, die kann ich ja in der Breite verändern.)

Habe es mal so umgeschrieben:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/perl
use strict;
use List::Util qw(max);

my $TERMWIDTH=80;
open(FILE, "bla");
my @a=<FILE>;
close(FILE);
chomp(@a);

my $max=max map { length } @a;
my $col = 0;
while(my $a = shift @a) {
        $col+=(1+$max);
        if ($col >= $TERMWIDTH) {
                $col = (1+$max);
                print "\n";
        }
        print $a." "x(1+$max-length($a));
}
print "\n";

View full thread Ausgabe von Fileliste in Spalten