arilou: (Meditate)
[personal profile] arilou
Не случалось ли кому из 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".

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

arilou: (Default)
Danil "Eleneldil G. Arilou" Lavrentyuk

February 2023

S M T W T F S
   1234
5678 91011
12131415 161718
192021222324 25
262728    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 23rd, 2025 03:52 pm
Powered by Dreamwidth Studios