Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: typeglob/symbolic reference question

by ikegami (Pope)
on Nov 04, 2010 at 02:51 UTC ( #869395=note: print w/replies, xml ) Need Help??


in reply to Re: typeglob/symbolic reference question
in thread typeglob/symbolic reference question

i like to read the ampersand in similar way to reading C, where it's literally "address of" operator.

It's never anything like the "address of" operator in Perl. In fact, it's often used to do the opposite (dereference a code ref).

so in that context the example line starting with ampersand would read: the address of an anonymous sub containing code/literal "color" is assigned the sub on the right hand side.

Which goes to show your way to read the ampersand is wrong. Nothing of the kind happens.

  • Comment on Re^2: typeglob/symbolic reference question

Replies are listed 'Best First'.
Re^3: typeglob/symbolic reference question
by aquarium (Curate) on Nov 04, 2010 at 05:05 UTC
    hi ikegami. dereferencing is literally accessing something at the address pointed by variable value. perl jargon is sigil...however perl does borrow many concepts (like referencing=~pointers nuts and bolts) from C. Maybe it's not the most useful concept (in my mindset) to bring across from C to perl with me...anyhow you can dereference a code reference in perl without the ampersand, so any argument about what ampersand actually does in perl is debatable, unless you actually see some requirement for it in compiled/assembled/running perl code. and it's not in current fashion for perl code afaik. maybe i should re-read the black book..but that's quite dated now.
    the hardest line to type correctly is: stty erase ^H

      Maybe it's not the most useful concept (in my mindset) to bring across from C to perl with me...

      Definitely, cause Perl's "&" never does anything similar to C's "&". Perl's "\" would be the closest to C's "&".

      anyhow you can dereference a code reference in perl without the ampersand

      $ref->(), although I don't see how the question relevant.

      so any argument about what ampersand actually does in perl is debatable

      Not really. It can be used to bypass prototypes (&func(...)), to call a func with parent's args (&func;), to dereference a code ref (&$ref) and surely more. None of them return an address (like C's "&") or anything similar (like Perl's "\").

      dereferencing is literally accessing something at the address pointed by variable value

      Not in any version of Perl. C pointers may be a fact of the implementation of Perl 5, but there is no language requirement for anything of the sort.

        I don't understand your disagreement. The quoted statement seems obvious to me. If your language can dereference, you have references, and if you have references, you have some form of addressing. Dereferencing is the act of finding what's referenced (pointed to) by that reference (address).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://869395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2020-10-29 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (274 votes). Check out past polls.

    Notices?