Title:HowtooverloadmodulewithoutmodifyingitinPerlKeyword:PerlmoduleoverloaddebuguserequiredifferenceunshiftINCTodebugaPerlscript,Imustaddsometracecodeinit.Thereare2filestobemodified.Oneismainplscript,anotherispmmodulefile.Iamnotallowedtomodifythemdirectly.Also,Idon’twanttoduplicatethewholeenvironmentbecauseit’sverybig.So,Icreateaworkingdirectoryandcopythose2files.Keepthedirectoryasoriginalstructure.originalstructureis/system/bin/thescript.pl/system/modules/package/TheModule.pm…myworkingdirectoryis/myworkarea/bin/thescript.pl/myworkarea/modules/package/TheModule.pmAftermodifiedmyTheModule.pm,Imustmakethethescript.pltoloadmymoduleinsteadoforiginalone.Thecodeinthescript.plaboutloadingmoduleis#!/somepathtoperl/bin/perluseFindBinqw($Bin);uselibqq{$Bin/../modules};usepackage::TheModule;…my$theModule=newpackage::TheModule;…Changeitas#!/somepathtoperl/bin/perluseFindBinqw($Bin);uselibqq{/system/modules};unshift(@INC,”$Bin/../modules”);requirepackage::TheModule;…my$theModule=newpackage::TheModule;…Then,thethescript.plwillcallthe/myworkarea/modules/package/TheModule.pm.Also,itcanuseothermodulesin/system/modules1.Purposeofunshiftuselibqq{/system/modules};unshift(@INC,”$Bin/../modules”);addoriginalpathintoINC,thenuseunshifttoaddthenewmodulesdirectoryatthebeginingoftheINC.2.Purposeofrequirerequirepackage::TheModule;tomaketheTheModuleloadatruntime.Thedifferencebetweenuseandrequireishere.http://www.geekinterview.com/question_details/17064标题:在Perl中如何让新代码取代原有代码关键部分:1.用unshift把包含新模块的路径放在INC的最前面2.用require取代use让模块在运行时加载Reference:http://www.cbi.pku.edu.cn/chinese/documents/perl/perl14.htmReference:http://www.geekinterview.com/question_details/17064