#!/usr/bin/perl use Module::Reload; require "test_mod.pl"; print "File Contents (1):\n"; read_file(); print "the control:\n"; test_pl(); undefSub('test_pl'); write_file("test_mod.pl","#!/usr/bin/perl\n\nsub test_pl {\n print \"zippy doo\";\n}\n\n\$hello=2;"); print "\n\n\n\n"; print "File Contents (2):\n"; read_file(); print "\n\n\n\n"; require "test_mod.pl"; Module::Reload->check; print "the test:\n"; test_pl(); print "\n\n\n\n"; write_file("test_mod.pl","#!/usr/bin/perl\n\nsub test_pl {\n print \"back to normal\";\n}\n\n\$hello=1;"); sub read_file { open( FILE, "< test_mod.pl" ) or die "Can't open test_mod.pl : $!"; while( ) { print; } close FILE; } sub write_file { my ( $f, @data ) = @_; @data = () unless @data; open F, "> $f" or die "Can't open $f : $!"; print F @data; close F; } sub undefSub { no strict 'refs'; my $name = shift; # save the glob... local *old = *{$name}; # and restore everything else local *new; foreach my $type (qw(HASH IO FORMAT SCALAR ARRAY)) { my $elem = *old{$type}; next if !defined($elem); *new = $elem; } *{$name} = *new; }