At 2:20 PM +0200 4/2/07, Rafael Garcia-Suarez wrote:
>On 02/04/07, Elizabeth Mattijsen <liz@dijkmat.nl> wrote:
>>What are ONCE blocks more than something like:
>>
>>my %done;
>>sub ONCE (&) {
>> my ( $code ) = @_;
>>
>> return if exists $done{$code};
>>
>> $code->();
>> $done{$code} = undef;
>>}
>>
>>my $variable;
>>ONCE { $variable = $_ } foreach 1..5;
>>print "variable = $variable\n";
>>=====================
>>variable = 1
>
>Those run the code once per thread. (if %done isn't shared).
Hmmm... if run before a thread starts, it will inherit. If not run
before a thread starts, it will run once inside the thread.
Different threads may get different initializations. What is wrong
with that?
>START blocks (not ONCE, after verification in Synopsis 4) run once per
>closure. See t/op/state.t for an example of code with a state variable
>in a closure, that gets its own state at each closure generation.
Ah, that's a different kettle of fish... ;-) Thanks for the clarification...
Liz
Thread Previous
|
Thread Next