The main program = testeval.pl ########################################## #!/usr/bin/perl -w # call it twice to get the 'redfined' warning &testeval; &testeval; sub testeval { # read a replaceable code segment from a # file containing the evalsub subroutne my $code = read_replacable_code("testeval_code.pl"); eval $code; if ($@) { print "error eval $@\n"; } # call the sub defined in the eval'd code &evalsub; } sub read_replacable_code { my $fname = shift; $code = ''; if (open (FCODE, $fname)) { while (my $line = <FCODE>) { $code .= $line; } close (FCODE); } return $code; } the replacable code segment - testeval_code.pl ########################################## sub evalsub { print "evalsub\n"; } results ########################################## [root@mma-qa-be01 nick]# ./testeval.pl evalsub Subroutine evalsub redefined at (eval 2) line 2. evalsub
In reply to Subroutine redefined error that I can't figure out by nickm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |