#! /usr/bin/perl -w use autouse Data::Dumper, qw{Dumper}; # Script to find the unused shell functions in slapd.scripts-common our @code; # Get all shell code from maintainer scripts foreach my $file ((<slapd.*rm>, <slapd.*inst>, <slapd.config>, <slapd.scripts-common>)) { open SCRIPT, "<$file" or die "Can't open $file: $!"; push @code, <SCRIPT>; close SCRIPT; } # Find all function declarations our @functions = map { /^(\w+)\s*\(\).*$/; } @code; # Find unused functions foreach $function (@functions) { @occurences = grep /$function/, @code; @invocations = grep { !/^$function\s*\(\)/ and !/#.*$function/ } @occurences; print "$function\n" if @invocations == 0; }