#!perl -w use strict; our $already_fixed = 1; # this won't show up # Put this right before the "uncleaned" part of the script starts my %initial_variables; BEGIN { %initial_variables = %main::; # make a copy at the start of the program } END { #use Data::Dumper; #warn Dumper \%initial_variables; #warn Dumper \%main::; # At the end, look what names came newly into being, and tell us about them: for my $key (sort keys %main::) { if( ! exists $initial_variables{ $key } ) { print "Undeclared global variable '$key' found\n"; my $glob = $main::{ $key }; if( defined *{ $glob }{GLOB}) { print "used as filehandle *'$key', replace by a lexical filehandle\n"; }; if( defined *{ $glob }{CODE}) { print "used as subroutine '$key'\n"; # so maybe a false alarm unless you dynamically load code?! }; if( defined *{ $glob }{SCALAR}) { print "used as scalar \$'$key', declare as 'our'\n"; }; if( defined *{ $glob }{ARRAY}) { print "used as array \@'$key', declare as 'our'\n"; }; if( defined *{ $glob }{HASH}) { print "used as hash \%'$key', declare as 'our'\n"; }; }; }; } no strict; $foo = 1; @bar = (qw(baz bat man)); open LOG, '<', *STDIN; sub foo_2 {} use strict;