开发者

Are these regular Perl subroutine calls?

I'm still trying to get a hang of Perl's OOP features. I'm confused about something, if I have a subroutine call like:

My::Package::sub_name($param1,$param2)

will this get "My::Package" sent as the first parame开发者_如何学编程ter? I'd tend to say no, but I'm not sure.


(As Manni says) It's the -> operator that unshifts the invocant to @_ (where the invocant is either a blessed object, or a bare class name). :: in the function name is just used for namespace disambiguation and does not change @_.

Posted as an answer as per Geo's suggestion, although I don't want to be a rep whore :)

It's described more in the docs: perldoc perlboot, perldoc perltoot.


Why don't you just try it?

Spoiler alert:

No, the first parameter will not be the package name.

However, when you do:

My::Package->sub_name( $param1, $param2 )

you will get the package/class name as the first parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜