What does the `->` syntax mean in Perl?

后端 未结 3 1273
盖世英雄少女心
盖世英雄少女心 2021-01-03 05:47
chdir($g_var->{g_loc});

I found this line in some perl code I am working with and I could not figure out what the -> means. I me

3条回答
  •  旧时难觅i
    2021-01-03 06:29

    This is what you get if you search for perlop (perl operators) on http://perldoc.perl.org. Perldoc, the on-version of it has undergone major improvements and frankly from all reference doc I like this the best.

    "->" is an infix dereference operator, just as it is in C and C++. If the right side is either a [...] , {...} , or a (...) subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. (Or technically speaking, a location capable of holding a hard reference, if it's an array or hash reference being used for assignment.) See perlreftut and perlref.

    Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name). See perlobj.

提交回复
热议问题