in reply to Contain yourselves please: THEORETICAL question about variable values being used as A PART of another variable's name.

Treat the expression giving the name of the variable as a reference.

So if the name is obtained by "specific_${var_name_modifier1}_var" and it's a scalar variable, you want

no strict qw( refs ); ${ "specific_${var_name_modifier1}_var" } = 123; say ${ "specific_${var_name_modifier1}_var" };
  • Comment on Re: Contain yourselves please: THEORETICAL question about variable values being used as A PART of another variable's name.
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Contain yourselves please: THEORETICAL question about variable values being used as A PART of another variable's name.
by Anonymous Monk on Dec 15, 2016 at 18:37 UTC
    That is terrible code.

      Which is one of the reasons we repeatedly state not to use such code.

      Dominus says it best.

        > Which is one of the reasons

        Not really, there are many reasons, but that's not part of it! :)

        Ikegami's code is just a condensed one liner version of

        $string= "construct variable name"; say $$string;

        not much different from dereferencing syntax.

        On another note: Someone is trying to troll here ATM, better don't feed. :)

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      Of course it is. That was already made extremely clear by the following:

      this is purely a curiosity and NOT for actual implementation anywhere....EVER. I know one should not do this i know what should NEVER EVER do this.....one should use hashes etc.... etc.....I know....

      So yeah, we shouldn't use symbolic references, which is why we ask perl to prevent us from using them by adding use strict; to our code. It's extremely clear that the OP knows this too, but they wanted to know how to use them anyway. Some low-level code (e.g. exporters, OO frameworks, namespace cleaners, etc) require using them, and its possible the OP is working on such code.