Being a perl forum and all here is a short ls type script
that you can configure to your hearts content. You can get all
sorts of info out of the file test operators if you want to generate
a custom listing like from ls -Cal, see perlman:perlop
Script takes one argument
[dir to list] or defaults to the cwd. We use ANSI escapes
to colour the text. The Term::ANSIColor module exports some constants
so we just say what color we want in the print.
#!/usr/bin/perl -w
use strict;
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
my $dir = shift @ARGV || '.';
opendir DIR, $dir or die "Can't open dir $!\n";
while (my $file = readdir DIR) {
if ( -d "$dir/$file" ) { # directory
print BLUE "$file\n";
} elsif ( -l "$dir/$file" ) { # symbolic link
print CYAN "$file\n";
} elsif ( $file =~ m/\.(?:pl|pm|cgi)$/ ) { # looks Perly
print GREEN "$file\n";
} elsif ( -x "$dir/$file" ) { # is executable
print YELLOW "$file\n";
} elsif (-f "$dir/$file" and -T "$dir/$file" ) { # is a Text file
print RED "$file\n";
} else { # none of the abo
+ve!
print "$file\n";
}
}
# Colors available:
# BLACK WHITE RED GREEN YELLOW BLUE MAGENTA CYAN
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|