#!/usr/bin/perl
$my_mode=0; 

if ($ARGV[0] =~ "-l"){
	print "long mode\n\n";
	$my_mode=1;
}

@my_results=`ls -l --full-time spam*`;
@output="";
$i=1;
$last_one=0;
$my_val="";
foreach $a (@my_results){	
 	@b=split /[ ]+/,$a;
	if($b[0] =~ /^[^d]..x/){
	if ($my_mode == 0){
		$my_val=$b[8];
		chomp($my_val);
		$my_val =~ s/spam-//g;
		if ($my_val !~ "\.pl" && $my_val !~ "cmds" && $my_val !~ "spam"){
print "$my_val\n";
		push  @output, ($my_val) ;
		}
	}else{
		print $a;
		}
	}
}
	if ($my_mode == 0){
		$l=0;
		print "\033[2J";
		print "\033[1;1HSPAMLESS cmds\n\n";
		$i=0;
		$width=20;
		$columns=$ENV{'COLUMNS'};
		$lines=$ENV{'LINES'};
		if($lines==0){
			print "You need to 'export LINES & COLUMNS' before running this command\n\n";
			exit();}
		$col=int($columns/$width);
		foreach $a (sort @output){
			printf "\033[%d;%iH%s$a", ($l+2), $c, ($DEBUG==1)?"$i $l $c ":"";	
			$c=int(($i%$col)*$width)+1;
			$l=int($i/$col)+1;   # 0 based math is better, but one based terms are
			$i++;
		}
		$l+=5;
		$i--;
		printf "\033[$l;1H$i Cmds Found.\n\n";
}
