这就是我想要实现的目标:
sub first { print "this is original first"; } *original_first = \&first; sub first { print "this is first redefined"; } original_first(); # i expect this to print "this is original first" first() # i expect this to print "this is first redefined"
我认为通过首先保存符号,我以后可以调用原始子程序(名称为original_first)并且也可以先调用,然后重新定义.但是,如果我调用original_first,我仍然会得到“这是第一次重新定义”.我需要做些什么来完成这项工作?
解决方法
这应该按预期工作:
sub first { print "this is original first"; } *original_first = \&first; *first = sub { print "this is first redefined"; };