The uncontrollable mass-import of core subroutine names by PDL is indeed something ... special. I guess it is fair to attribute it to the fact that big parts of it were written in the previous century, when extensive @EXPORT lists were rather popular. While it is f**cking convenient most of the times, apparently it can bite you.

That said, the combination of srand and rand is special also by two other facts: 1) the functions are not independent of each other, and 2) PDL did override srand but not rand, it has a function random instead. This might be indeed the only pitfall of PDL's exports: I would expect all others to behave like their CORE equivalents.

I see two ways around it (that is, without changes in PDL):

The following two examples give consistent (but different) results each:

perl -MPDL::Lite -E "srand(3); say rand();" perl -MPDL -E "srand(3); say random();"

Anecdote: Once I got bitten by export list the other way around: One of my programs also used Math::Trig. This overrides a list of (non-core) functions also provided by PDL, but ... of course it doesn't provide the magic (and gave strange error messages) when called with an ndarray as an argument.


In reply to Re: PDL and srand puzzle by haj
in thread PDL and srand puzzle by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.