me.at.coding
me.at.coding

Reputation: 17614

Perl operator meaning :: and ->

I am new to Perl and I am wondering what :: and -> mean and if they mean the same or are different? I mostly saw them on variable/method calls on objects? Thanks for any hint!

Upvotes: 3

Views: 1157

Answers (1)

tripleee
tripleee

Reputation: 189327

The :: as in $main::variable is a namespace separator; this refers to $variable in package main. The separator is not an operator at all.

The -> as in $variable->{'key'} is a dereference operator. This is how you refer to the values of a hash which the scalar $variable is a reference to (or similarly for references to arrays, with square brackets instead of curlies).

So no, the two constructs are hardly related at all.

Upvotes: 4

Related Questions