swestrup: (Default)
[personal profile] swestrup
I would say that the inner workings of Perl were grotty, were it not that I know of many nice grottos far less grotty than perlguts.

So, my discovery of today is that the following code works:

eval{ use Foo::Bar }
eval{ use Foo::Bar } if $@;
eval{ use Foo::Bar } if $@;
die $@ if $@;

But this doesn't:

sub tryit($) { for(1..3){ eval $_[0]; return 1 if !$@ } die $@; }
tryit("use Foo::Bar");

Or, that is, it claims to work, but the exports of Foo::Bar are nowhere to be found...

Anyway, I finally realized I only called tryit 6 times in my code so I simply pasted in 6 copies of the first solution. One day I'll figure out what I SHOULD have coded, when I'm not under such deadline pressure.

Oh, and the above is necessary since, under Win98, if I fork two perl tasks and they load the SAME libraries, then every now and again one of the loads fails for no reason. Retrying twice seems to limit the scope of the problem. FIXING the problem is left as an excercise for the reader.

Date: 2003-06-28 08:05 am (UTC)
From: [identity profile] sps.livejournal.com
I don't think the eval {} and eval "" constructs are even related. eval {} only does trap handling, but otherwise is just a block construct; in particular it still compiles at compile time. eval "", on the other hand, fires up a new compiler at runtime, when all static procesing is long over, so the only environmental linkage that's posible by this point is dynamic. That's sort of what it's for.

So I don't think there's a mystery there.

You might try BEGIN { eval "" }, if that's the semantics you're after.

There's also a note in the docs that BEGIN { fork } is broken on machines without 'real' processes, if that's what you're doing (because the Perl interpreter fakes forking by thread duplication, but apparently the parser doesn't run in a real thread, or something like that).

Finally, not that "Support for concurrent interpreters and the fork() emulation was implemented by ActiveState, with funding from Microsoft Corporation." Of which you may make what you will.

January 2017

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 27th, 2025 11:05 am
Powered by Dreamwidth Studios