Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Function-frequency/Tcl/function-frequency.tcl
Normal file
28
Task/Function-frequency/Tcl/function-frequency.tcl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package require Tcl 8.6
|
||||
|
||||
proc examine {filename} {
|
||||
global cmds
|
||||
set RE "(?:^|\[\[\{\])\[\\w:.\]+"
|
||||
set f [open $filename]
|
||||
while {[gets $f line] >= 0} {
|
||||
set line [string trim $line]
|
||||
if {$line eq "" || [string match "#*" $line]} {
|
||||
continue
|
||||
}
|
||||
foreach cmd [regexp -all -inline $RE $line] {
|
||||
incr cmds([string trim $cmd "\{\["])
|
||||
}
|
||||
}
|
||||
close $f
|
||||
}
|
||||
|
||||
# Parse each file on the command line
|
||||
foreach filename $argv {
|
||||
examine $filename
|
||||
}
|
||||
# Get the command list in order of frequency
|
||||
set cmdinfo [lsort -stride 2 -index 1 -integer -decreasing [array get cmds]]
|
||||
# Print the top 10 (two list items per entry, so 0-19, not 0-9)
|
||||
foreach {cmd count} [lrange $cmdinfo 0 19] {
|
||||
puts [format "%-20s%d" $cmd $count]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue