I'm always an very curious guy and i just because of that i made a little
script that analyises my scripts, extracts the subs, counts lines,
mys, uses, subs, etc... maybe some of you are as courious as i am
but too lazy to do that for yourself, so i want to share it with the
perl community.
totally uncommented, unsupported and without any warranty ;-)
it's just a little program with few functions but maybe you want to
add some. If you make changes or want to suggest something,
mail the changed code/suggestion to me, plz :-)
usage :
perl <scriptname.pl> <ScriptToAnalyse.pl>
result :
writes all subs into the subdirectory 'subs' and several other stats
into 'subs/misc' (directorys must exist)
i'm just a newb and i'm always open for suggestions how to improve
things i made :)
yours
Jaschar Otto aka whoever
use strict;
my ($insub, $bracks);
my ($currs, $line);
my ($subnumber);
my ($usenumber);
$line = 0;
$currs = "main";
$subnumber = 0;
$usenumber = 0;
open FILE,"$ARGV[0]";
open MAIN,">subs/misc/main.txt";
open DEVA,">subs/misc/vars.txt";
open SUBS,">subs/misc/subs.txt";
open USES,">subs/misc/uses.txt";
open MISC,">subs/misc/misc.txt";
print SUBS "Sub#\t\tLine\t\tName\n";
print USES "Use#\t\tLine\t\tName\n";
while (<FILE>) {
$line += 1;
if (($line == 1) && ($_ =~ /^\#!/)) {
my ($x);
$x = $_;
$x =~ s/#!//;
$x =~ s/\s+.*//;
print MISC "Perl path\t: $x";
}
if ($_ =~ /^#/) {
$_ = "";
}
if (($insub == 0) && ($_ !~ /^sub /)) {
print MAIN "$_" if ($_ ne "\n");
}
if ($_ =~ /^sub /) {
$subnumber += 1;
$insub = 1;
$_ =~ m/^sub (\w+) /;
$currs = $1;
print SUBS "$subnumber\t\t$line\t\t$currs\n";
open SUB,">subs/$currs.txt";
$bracks = 1;
} elsif ($_ =~ /\{/) {
$bracks += 1;
} elsif ($_ =~ /\}/) {
$bracks -= 1;
}
if (($insub) && ($bracks == 0)) {
$insub = 0;
$currs = "main";
print SUB "}\n";
close SUB;
} elsif (($insub) && ($bracks > 0)) {
print SUB "$_";
}
if ($_ =~ /my(\s*)\(/) {
my ($cusu, $myline);
$_ =~ m/(\t*)(.+)/;
$cusu = $currs;
$cusu .= " " while (length($cusu) < 12);
$myline = $_;
$myline =~ s/\t//g;
$myline =~ s/\s//g;
print DEVA "sub $cusu \t-> $myline\n";
}
if ($_ =~ /use (.+)/) {
$usenumber += 1;
print USES "$usenumber\t\t$line\t\t$1\n";
}
}
print MISC "Total lines\t: $line\n";
print MISC "Total uses \t: $usenumber\n";
print MISC "Total subs \t: $subnumber\n";
close FILE;
close MAIN;
close DEVA;
close SUBS;
close USES;
close MISC;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]