in reply to References quick reference

Well done, but you have omitted the fact that dereferencing an anonymous function means calling it:
&$aSub(@args); $aSub->(@args); # This notation due to merlyn
and at this point if people wonder why a method call looks like a dereferencing operation, they should give themselves brownie points because it is. When you call bless on a reference, it is not the reference that is blessed, it is the thing that the reference points at. And a method call is really a matter of dereferencing the reference in a way that is looking for a method. Consider:
package foo; sub bar { print "foobar strikes again!\n"; } package main; # Create and throw away an object bless \$x, "foo"; # But the blessing is not forgotten! (\$x)->bar();
This detail was pointed out to me by merlyn in chatter about a week ago. At first it surprised me, but then I thought about it and it made a lot of sense. After all if I have 10 references to the same thing, shouldn't dereferencing any of them be equivalent? Doesn't a method call look like just dereferencing...?

And so to your list you can add calling an anonymous subroutine and making a method call as dereferencing operations.

Replies are listed 'Best First'.
(tye)Re: References quick reference
by tye (Sage) on Apr 05, 2001 at 09:49 UTC

    you have omitted the fact that dereferencing an anonymous function

    Quite intentionally. I didn't want to distract from the topic: dereferencing "data structure references". I wanted people to be able to let that sink in and then never worry about it again. Perhaps a title change is in order, though I don't want a title that will scare people off either. (:

    Had I chosen to cover code references, then I would have been more detailed than what you've discussed above. I started to and then realized I didn't have handy the details required to cover that topic in a manner deserving of the label "tutorial" (and also realized that it didn't fit in anyway).

    I also didn't talk about creating references, symbolic references, blessed references, closures, ref, UNIVERSAL::isa(), references to globs, to the IO chunks of globs, to compiled regular expressions, nor to any other types of things that Perl lets you have a reference to.

    All of those break some of the above rules and discussing them would distract the reader from once and for all getting those rules down. I also lump data structure references together in my head while thinking of code references separately from glob references separately from...

    So, no, I'm not going to add your two things to my list. q-:

            - tye (but my friends call me "Tye")
Re: Re (tilly) 1: References quick reference
by demerphq (Chancellor) on Jun 28, 2003 at 09:25 UTC

    dereferencing an anonymous function

    Just to clarify, its not a question of anonymous functions (unless your definition of anonymous is the same as "reference to a"). Any valid reference to a function can be called as you say.


    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...