#!/usr/bin/perl

use 5.038.2;

my @dir = glob "*";

for my $file (@dir){
    next if ($file =~ /\s/);            # good people don't put spaces in a filename
    next if ($file =~ /\~/);            # backup
    next if ($file =~ /\.sha/);         # sign
    next if ($file =~ /\.html/);        # data

    next unless (-T $file);             # only plain text files (heuristic)
    
    my $header = `head -n 1 $file`;     # sólo la primera linea es posible she bang
    my $flag = 0;
    my $lin = 0;
    if ($header =~ /^\#\!/){	
	print "She bang plain file     $file     : ";
	if ($header =~ /(\w*sh)/){
	    my $shell_type = $1;
	    print "Shell file ($shell_type).";
	}elsif ($header =~ /perl/){
	    my @head = `head $file`;
	    for (@head){
		if (/use\s+(5\S+)/){
		    my $ver = $1;
		    $lin = `cat $file | wc -l`;
		    chomp $lin;
		    print "Perl   version $ver   lines $lin. ";
		    $flag = 1;
		    last;
		}
	    }
	    
	    if ($flag == 0){
		$lin = `cat $file | wc -l`;
		chomp $lin;
		print "Perl script. Undef version  lines $lin. ";
	    }
	}elsif ($file =~ /\.pl/i){
	    print "Maybe a Perl script. "
	}elsif ($file =~ /\.pm/){
	    print "Maybe a Perl module of code. "; 
	}elsif ($header =~ /local/){
	    print "Other local script. ";
	}elsif ($header =~ /python/){
	    print "Maybe a Python script. Ask in Python forums ";
	}elsif ($header =~ /ruby/){
	    print "Maybe a Ruby script. Ask a girl called...";
	}
	say "";
    }
}

exit 3;

__END__

tudu:

Detectar ruby
  
Contar lineas siempre
  
El «algo sh» cambiarlo por lo que sea 

