K
krystian.wojtas
Hi
The program I'm working on is creating a database using the built-in pack function. It needs to add a feature which makes some statistics about data usage by particular arrays.
The best approach I think is to use the Aspect module and insert some additional code after invoking the pack method. But as far as I see, hijacking the built-in function is not working. Could you confirm this?
In this case I prepared a wrapper function which is like this:
sub pack_wrapper { pack(@_); }
But it doesn't work. It looks like the pack function forces the list @_ to be passed in scalar context. In this case, pack gets the size of the array instead of its content.
The pack function hasn't a fixed number of arguments, so I cannot pass it directly like this:
sub pack_wrapper { pack($_[0], $_[1]); }
Probably I can use meta-programming to generate the code which invokes pack with all arguments explicitly depending on the list size. But such a workaround feels really awful for me.
Is it possible to pass my list @_ in list context to the pack function in some perl clean way?
Thanks for your answer and sorry if my question is obvious for you, I have already spent some time and cannot find the right solution.
Best regards,
Krystian
The program I'm working on is creating a database using the built-in pack function. It needs to add a feature which makes some statistics about data usage by particular arrays.
The best approach I think is to use the Aspect module and insert some additional code after invoking the pack method. But as far as I see, hijacking the built-in function is not working. Could you confirm this?
In this case I prepared a wrapper function which is like this:
sub pack_wrapper { pack(@_); }
But it doesn't work. It looks like the pack function forces the list @_ to be passed in scalar context. In this case, pack gets the size of the array instead of its content.
The pack function hasn't a fixed number of arguments, so I cannot pass it directly like this:
sub pack_wrapper { pack($_[0], $_[1]); }
Probably I can use meta-programming to generate the code which invokes pack with all arguments explicitly depending on the list size. But such a workaround feels really awful for me.
Is it possible to pass my list @_ in list context to the pack function in some perl clean way?
Thanks for your answer and sorry if my question is obvious for you, I have already spent some time and cannot find the right solution.
Best regards,
Krystian