in reply to Re: Callback function in xsubpp (each)
in thread Callback function in xsubpp

Thank you for the reply. So, is there any way to retain the iterator position? Or, should I always copy the hash into another hash and then call the subroutine?
  • Comment on Re^2: Callback function in xsubpp (each)

Replies are listed 'Best First'.
Re^3: Callback function in xsubpp (xs--)
by tye (Sage) on Jul 31, 2013 at 06:47 UTC

    What I would do is honor my best practice of not manipulating Perl data structures from XS code and just iterate over the keys in regular Perl code using for my $key ( keys %hash ) [which makes a copy of just the keys].

    - tye        

      This is what I did to solve the problem. Firstly, I took all the keys in the hash and pushed them into an array defined using AV*. Then, I iterated over this array by popping the topmost element during every loop iteration. In parallel, I updated the hash with the results and executed the callback function too.

      Using the array instead of keys ensured that the iterator does not get reset. Also, the array would be empty when I exit the function.

      Thank you Tye for pointing out the mistake that I had done in the program.

      Completely agree with you. But, my XS function is going to run for long time (sometimes more than a day). At this point of time, I will be calling the Storable::store() in the callback routine to save the intermediate status. This will help me in checking the progress, whenever I need to. Would be happy to know if you have any better solution for this.