in reply to Re^2: Indirect variable expansion
in thread Indirect variable expansion

Furthermore, -M doesn't seem to throw an error for unknown modules.
Yes, it does:
perl -MNotRight -e 0 Can't locate NotRight.pm in @INC (you may need to install the NotRight + module) (@INC contains: ...

Replies are listed 'Best First'.
Re^4: Indirect variable expansion
by LanX (Saint) on Nov 18, 2024 at 14:57 UTC
    > Yes, it does:

    Well obviously not for me and the code I posted!

    update

    the problem seems to be bash related, the -M$M doesn't expand the $M I've just set. But Perl's sub-process has the correct ENV.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Well, yes. At the time the variable substitution occurs, the variable has not been set yet. eg.:

      $ quux=foo echo $quux $

      "Fix" it by separating the one command into 2:

      $ quux=foo; echo $quux foo $

      It isn't just bash, BTW. Any Bourne-compatible shell should behave like this.


      🦛

        You would still have to export it to see it in the perl process:

        $ export M=MyMod $ perl -M$M -E 'say $ENV{M}->VERSION' $ unset M

        Or just do it in a subshell to keep your environment clean:

        $ (export M=MyMod; perl -M$M -E 'say $ENV{M}->VERSION')