Someone has the idea of ββusing an array variable instead of the array (list) literal in a use function expression, for example:
my @list = qw(foo zoo); use Module @list;
instead
use Module qw(foo zoo);
So she writes, for example:
my @consts = qw(PF_INET PF_INET6); use Socket @consts; printf "%d, %d\n", PF_INET, PF_INET6;
which seems to work as expected:
2, 10
Then she does this with another module, for example. Time::HiRes . Instead
use Time::HiRes qw(CLOCK_REALTIME CLOCK_MONOTONIC); printf "%d, %d\n", CLOCK_REALTIME, CLOCK_MONOTONIC;
0, 1
she does:
my @consts = qw(CLOCK_REALTIME CLOCK_MONOTONIC); use Time::HiRes @consts; printf "%d, %d\n", CLOCK_REALTIME, CLOCK_MONOTONIC;
0, 0
It suddenly does not work, as if it was working with the Socket module! There is something bad here.
(.. he is in a non-strict environment. If she used use strict , she would even be mistaken. On the other hand, she has no hint of everything in her first seemingly working example - even when she use strict; use warnings; use diagnostics there.)
Now she wants to learn this strange behavior. Requests the import of an empty list:
my @consts = (); use Socket @consts; printf "%d, %d\n", PF_INET, PF_INET6;
2, 10
surprisingly works, but probably it is not, for example:
use Socket (); printf "%d, %d\n", PF_INET, PF_INET6;
0, 0
Then she delves a bit into these modules and realizes that the difference between the two modules is that these constants / are not @EXPORT ed respectively.
Her conclusion is that
use Module @list does not work as it expects.
What would be the best explanation? What is she doing wrong? What is the correct way to use a predefined array in a use statement?