in reply to Dereferencing code refs with & vs. ->()

"I prefer the former, since that's the way I'm used to dereferencing other things."

You don't actually use -> to de-referencing, you use it to access a member of a collection. When you dereference a hash or an array, you will use @ and %. In this sense, &$thingy holds more consistancy there.

-> fits well with class method, as class can be viewed as a collection of properties and methods.

  • Comment on Re: Dereferencing code refs with & vs. ->()

Replies are listed 'Best First'.
Re^2: Dereferencing code refs with & vs. ->()
by sauoq (Abbot) on Sep 23, 2005 at 01:43 UTC
    You don't actually use -> to de-referencing, you use it access a member of a collection.

    No, you use {} and [] to access a member of a collection. You use -> to dereference references. That's why it is called a "dereference operator" in perlop. (Specifically, it's called an "infix dereference operator" which helps to describe the syntax.)

    Update: I imagine your confusion stems from the fact that it must be used in conjunction with {}, [], or () in order to be useful. (Hence "infix" btw.) Still, it's doing the same job as the leading dollar sign ($) in $$thingy[0].

    -sauoq
    "My two cents aren't worth a dime.";