本文介绍了Php / perl类/包字段定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 由于新年,我的大脑必须运行缓慢,但是我错过了定义包裹字段的 技巧。 In php,我会这样做: ---- <?php class MyObj { var $ param1; 函数MyObj(){$ this-> param1 =" Hello" ;;} 函数Hello(){echo $ this-> param1;} } $ test = new MyObj; $ test-> Hello(); ?> ---- 然而这似乎不是正确的perl翻译: ---- 包MyObj; 我的$ param1 ="" ;; sub new { my $ newobject = {}; 祝福$ newobject; 我的$ param1 =" Hello" ;; 返回$ newobject; } sub你好{ 打印我的$ param1; } $ test = new MyObj ; $ test->你好(); ---- 创意有人吗? (除了切换到php,我不幸不能)。 PS:我试过先在perl新闻组上发帖,但谷歌团体 didn似乎心情不好(comp.lang.perl不存在,rofl)。 解决方案 param1; 函数MyObj(){ this-> param1 =" Hello" ;;} 函数Hello (){echo this-> param1;} } My brain must be running slow because of New Year, but I''m missing thetrick to define fields for a package. In php, I''d do:----<?phpclass MyObj{var $param1;function MyObj(){$this->param1 = "Hello";}function Hello(){echo $this->param1;}}$test = new MyObj;$test->Hello();?>----However this doesn''t seem to be the correct perl translation:----package MyObj;my $param1 = "";sub new {my $newobject = {};bless $newobject;my $param1 = "Hello";return $newobject;}sub Hello {print my $param1;}$test = new MyObj;$test->Hello();----Ideas anyone ? (besides switching to php, which I unfortunatly can''t). PS: I tried posting on the perl newsgroup first, but Google Groupsdidn''t seem to be in the mood ("comp.lang.perl doesn''t exist", rofl). 解决方案 param1;function MyObj(){this->param1 = "Hello";}function Hello(){echothis->param1;}} 这篇关于Php / perl类/包字段定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-27 10:14