Todd Shifflett wrote: > > > I have a subroutine which makes a number of recursive calls and uses as > input a scalar reference from an array. I am able to retrieve the > number from the reference, however, I would also like to print out the > array and index information that was used. > > > Ultimately I get this: > > (A) SCALAR(0x4759c) SCALAR(0x47680) SCALAR(0x4759c) > > > where the input was: > > (B) \$array[0] \$array[1] \$array[0] > > > is there any way for me to work backwards and pull the array name and > index (B) from: (A) SCALAR(0x4759c)? > > -todd
you don't need to work backward to get your stuff back. when your recursive calls ended, the value of the previous function call will be pop off the stack and returned back to you. you can easily put a ref check to catch the reference returned by those and de-reference them before using them. However, the index will be lost. Unless you have keep them somewhere separately (and manually), I don't think you will be able to get back the index. Perl (and most programming languages) only uses the index as a memory offset to find a particular value inside a chunk of memory. when you pass something like $array[0] to a function, only the value is passed. The function itself knows absolutely nothing about where the value is coming from. ie: call_a_function($array[1]) call_a_function(100) call_a_function($hash{abcd}) to the call_a_function() function, it can't distinguish that the first call is passed an array element, the second is a constant and the third one is a hash value. does that make sense? david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]