#!/usr/bin/perl require 5; #desc{simple ls clone} # This is a simple ls clone. # Documentation is at the end of this file. # Use perldoc to read it. # ########################################################################### # Time-stamp: "2005-08-19 01:33:07 ADT" use strict; use locale; # nice sorting # the MSWin shell doesn't do globbing for us. @ARGV = map m/[\*\?]/ ? glob($_) : $_, @ARGV if $^O eq "MSWin32"; if(@ARGV == 1 and -d $ARGV[0]) { chdir($ARGV[0]) or die "Can't read $ARGV[0]: $!\n"; splice @ARGV; } unless(@ARGV) { opendir(INDIR, ".") || die $_; @ARGV = sort {lc($a) cmp lc($b) or $a cmp $b} grep {; $_ ne '..' and $_ ne '.' } readdir(INDIR); closedir(INDIR); } my $size; foreach my $item (@ARGV) { if(-l $item) { $size = '=' } elsif(-d _ ) { $size = '-' } elsif(-f _ ) { $size = -s _; # And add commas... while( $size =~ s/^([-+]?\d+)(\d{3})/$1,$2/ ) {} } else { $size = '?' } printf "%11s %s\n", $size, $item; } exit; __END__ =head1 NAME l -- a simple minimal ls clone =head1 SYNOPSIS % l 39,967 Slash_Utility_Data_Data.pm - snapshots.tar 141,978 template-pocketref.rtf 2,449 test.txt 394,020 The_Perl_Review_0_0.pdf 585 todo.txt - Torgo =head1 DESCRIPTION This is an extremely simple-mindend C clone, motivated mainly by the fact that I couldn't get C to put commas in the file sizes. =head1 MSWIN NOTES Save this file as F and put in directory in your path. In the same directory, create a batch file F consisting of this: @echo off perl -S l.pl %1 %2 %3 %4 %5 %6 %7 %8 %9 Or possibly: @echo off perl -S l.pl %1 %2 %3 %4 %5 %6 %7 %8 %9 |more =head1 AUTHOR Sean M. Burke, sburke@cpan.org =cut