![]() |
|
Just another Perl shrine | |
PerlMonks |
PDL and srand puzzleby syphilis (Archbishop) |
on Jun 04, 2024 at 11:03 UTC ( [id://11159773]=perlquestion: print w/replies, xml ) | Need Help?? |
syphilis has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I pondered elsewhere over the reason that the following one-liner produced a different result each time it was run: It was explained to me that the PDL module exports its own srand() function - a function that silently clobbers perl's srand() function, and does not seed perl's pseudo-random generator. I was surprised, firstly, that PDL would do such a thing. Why don't they call their srand() function something like (eg) pdl_srand() ? Then, secondly, I was surprised that perl would allow its srand() function to be clobbered in this way, without so much as a whimper. Not even the loading of strict.pm or warnings.pm leads to a warning that srand() is no longer what I think it is. Thirdly, I wondered how one might protect oneself from such a trap. All I could think of is to replace the srand(3) call in my one-liner with CORE::srand(3) .... is there another way ? It's going to get rather tedious If one starts sticking a "CORE::" prefix in front of every perl core function call, just in case one of the loaded modules has overridden that particular perl core function. And I'm not seriously suggesting that I'm about to start doing that. This is the first time I've ever struck such an issue, so I reckon it's a very rare scenario. What do others think about the points I've just raised ? For the purpose of playing around with this I created the following module (OverRider.pm): Then I placed that file in one of my @INC directories and ran: Cheers, Rob
Back to
Seekers of Perl Wisdom
|
|