Eleneldil G. Arilou (arilou) wrote,
Eleneldil G. Arilou
arilou

PerlXS и @_

Не случалось ли кому из xs вызывать обратно перловую функцию, желая прокинуть ей неизменнённый @_ ? А то в man perlcall в описании G_NOARGS сказано, что вроде как это можно, а на практике - вызываемая функция параметров не получает. ЧЯДНТ?


Фрагмент из man perlcall:

G_NOARGS

Whenever a Perl subroutine is called using one of the call_* functions, it is assumed by default that parameters are to be passed to the subroutine. If you are not passing any parameters to the Perl subroutine, you can save a bit of time by setting this flag. It has the effect of not creating the @_ array for the Perl subroutine.

Although the functionality provided by this flag may seem straightforward, it should be used only if there is a good reason to do so. The reason for being cautious is that even if you have specified the G_NOARGS flag, it is still possible for the Perl subroutine that has been called to think that you have passed it parameters.

In fact, what can happen is that the Perl subroutine you have called can access the @_ array from a previous Perl subroutine. This will occur when the code that is executing the call_* function has itself been called from another Perl subroutine. The code below illustrates this

sub fred
{ print "@_\n" }

sub joe
{ &fred }

&joe(1,2,3);

This will print

1 2 3

What has happened is that "fred" accesses the @_ array which belongs to "joe".

Tags: perl, work
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 6 comments