Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

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

The memory address is the numeric version of the reference. Some sample code follows. As an added bonus, it illustrates the use of the mysterious "P" unpack() template.

#!/usr/bin/perl -wl use strict; my $target = 'IHBT'; print "target contains : ``$target''"; # Numify the reference, and derive a pointer from it. my $target_address = \$target + 0; my $native_version = pack 'L', $target_address; my $pointer = pack 'P', $native_version; print "target address : ", sprintf('%x', $target_address); # Walk Perl's variable structures. # This code depends on Perl's current implementation. I advise # against using it in production code. my $sv = unpack('P4', $native_version); print "deref'd packed (sv) : ", sprintf('%x', unpack('L', $sv)); my $pv = unpack('P4', $sv); print "deref'd sv (pv) : ", sprintf('%x', unpack('L', $pv)); my $value = unpack('P' . length($target), $pv); print "deref'd pv (value) : ``$value''\n";

-- Rocco Caputo -

In reply to Re: How to get the variable or function address in memory? by rcaputo
in thread How to get the variable or function address in memory? by hash

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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2022-08-13 21:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found