in reply to How do create a variable in another package in Perl?

There's no real need to "create" variables in another packages, because they are entries in the symbol table that can autovivify. Nonetheless you can do something like @YourPackge::VariableName = (1, 2, 3);

Though it is rare that this is a useful and a good idea. Maybe try to explain what you want to achieve in the end, then we can think about better approaches. It could be an XY Problem.

(For example it might be better to export variables from a module that you use in the namespace in question.)

Replies are listed 'Best First'.
Re^2: How do create a variable in another package in Perl?
by PerlOnTheWay (Monk) on Dec 12, 2011 at 09:03 UTC
    This is needed when the VariableName and the value of the variable(here (1,2,3)) are both determined on the fly

      In which case it isn't needed. Use a hash instead, or maybe some other construct entirely. Show us sample code where you think such a thing is needed and we'll show you a much better way to do it.

      True laziness is hard work

      Hello, I have small joke for you :D

      <GoodHumor>

      I agree with moritz :) there is a strong suggestion of an interface design problem, a strong suggestion for a need to just pass args

      Here is my complete analysis

      • +1 key phrase "in another package"
      • +1 newbee key phrase "in Perl"
      • +1 asking for the syntax
      • +1 while posessing the key keyword (package) to find the correct syntax
      • +1 key phrase "is needed"
      • +1 key phrase "on the fly"