Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

First, the most important difference between C pointers and Perl references is that there is no pointer arithmetic in Perl.

Second, in answer to your questions:

  1. The @_ array is special in Perl. On entry to a sub, it contains aliases to the arguments that were passed; $_[2] = 42; will set whatever variable was used as the third argument to 42. On line 28 of your code, $pointer_to_diff will itself be set to the difference; note that printing it emits an integer instead of a reference debugging value. On line 31, you pass a newly-constructed reference to $diff instead; that reference is itself an SV, so its value gets overwritten just before it is discarded. The $diff variable itself is never actually set. Devel::Peek is likely to be helpful here.
  2. As an lvalue, it means to assign to the variable to which the reference points. Since $res is itself a reference to the alias of the parameter that was passed in, this will replace the value that was passed in. On line 28, that is the $pointer_to_diff variable. On line 31, that is an anonymous temporary constructed to hold a reference to $diff.
  3. The earlier two answers answer this as well.

Lastly, read the documentation, particularly, perlreftut, perlref, and perldsc.


In reply to Re: Pointers and References by jcb
in thread Pointers and References by Leudwinus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-06-13 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (54 votes). Check out past polls.

    Notices?