in reply to no strict "refs" and require

Expanding variables in strings is covered in the FAQ: How can I expand variables in text strings.

-Blake

Replies are listed 'Best First'.
Re: Re: no strict "refs" and require
by little (Curate) on Feb 12, 2002 at 23:03 UTC
    the way desribed in that FAQ is the way which I use to do it :-) BUT that causes an error when running under strict pragma.
    So my Question is, which one is the other way (that doens't cause strict to die with a nice warning about string "blabla" not allowed while strict refs) _and_ not explicitely saying 'no strict "refs"' ? Because the latter one gives me that strange feeling or am I paranoic here?

    Have a nice day
    All decision is left to your taste
      The faq covers three different approaches. The first only works with globals and is not strict compliant. The second works with lexicals or globals and is strict compliant. The third shows how one could accomplish a similiar task using hash keys instead of variable names. I'd recommend either of the last two.

      -Blake

        safe as described in the faq

        $line =~ s/\$(\w+)/${getValue(\%myVars,\$1);}/sgex;

        but how do I get the defined skalars from the required script into my hash? that would be a way that I would prefer

        Have a nice day
        All decision is left to your taste
Re: Re: no strict "refs" and require
by little (Curate) on Feb 13, 2002 at 02:01 UTC
    As I said before, the script works as intended.
    If one would write "$zu" in a Template he would get an empty string as I don't want to expose script internals just by error.
    # But if I change these lines in sub getValue from ... # here starts the nightmare # so the provide hash had no key with such name } else { # I FEAR THIS no strict "refs"; # uhm, but it exists, in our namespace ? in our scope? besides +? if (defined $$var){ # if so, then take the value of the skalar $result = $$var; } else { warn "undefined Variable $var requested!"; } } ... #to } else { $result = '$'.$var; $result =~ s/(\$\w+)/$1/eeg; }
    I don't get an error
    • BUT a warning in my log stating that $var has not been imported
    • BUT one would get the current value of $zu
    which is exactly what I try to avoid, besides, then he gets an empty string for the skalars defined in the required script.

    I wouldn't ask if I had a clue on this ;-)