Newsgroups: comp.lang.perl, alt.hackers
Followup-To: comp.lang.perl
From: lw...@netlabs.com (Larry Wall)
Date: 28 May 92 22:59:35 GMT
Local: Thurs, May 28 1992 6:59 pm
Subject: Re: Can I take the address of a Perl variable?
In article <rantapaa.706981...@s6.math.umn.edu> ranta...@s6.math.umn.edu (Erik E. Rantapaa) writes:
: Is there ANY possible way of taking the address of Perl variable? : Yes, I know that the Perl manual states that there is no address-of : operator like C has and that such an operator goes against the : entire philosophy of Perl, BUT inquiring minds want to know. That's what the "p" template spec for pack does, just so happens... : Also, if it were possible to determine the address of a variable, In general, it's safe. The address of a string will stay the same as long : While on this the train of thought, I suppose I should ask the dual I'm tempted to say "Yes, it's possible," and leave it at that. However, #!/usr/bin/perl # The following block would ordinarily be "required". $str_tmpl = "LLdLLcccc"; $fakestr = pack($str_tmpl, 0, 4, 0.0, 4, 0, 1, 0, 0, 0); substr(*fakestab, 4, 4) = pack("L", $fakeaddr); sub main'peek { sub main'poke { $targ = "hi there"; $addr = unpack("L", pack("p", $targ)); print &peek($addr),"\n"; It would probably want some bulletproofing for any real use, if there But for amazing your friends and bewildering your enemies, it might come Mind you, there's absolutely no guarantee that this will work at any Larry You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||