Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Reading and producing variable lists (w/o hashes!)

by why_bird (Pilgrim)
on May 01, 2009 at 10:23 UTC ( #761249=note: print w/replies, xml ) Need Help??

in reply to Reading and producing variable lists (w/o hashes!)

I believe what you're trying to do is read in a bunch of names from a file, and then have those names available to use as variable names in your code? Is that right?

I remember once trying to do something similar, and eventually convincing myself that it was a struggle to do for a reason. For a start, it's a huuuuge security risk, which makes it bad practice, whether or not this code is going to be used by anyone else.

Perhaps this is an example of an X-Y problem, where you're not telling us what you're trying to achieve in the long run, or why you've chosen this particular method. Or maybe you're just doing it for the hell of it, because it seems like a fun thing to do, or just to find out if it can be done.

If the former, if you can outline your goal and what you've tried so far, I'm sure people will give you great suggestions as to how to proceed. This is the case in which not using 'use strict' may well come back to haunt you, unless you really know what you're doing! If the latter, good on you, and again I'm sure people will help you out.

I know this wasn't much practical help, but I think I'm echoing what was said above by almut, in that the more detail you give, the better and more useful people's answers will be.

I for one am curious about what you want to use this for!


update:added link

Those are my principles. If you don't like them I have others.
-- Groucho Marx
  • Comment on Re: Reading and producing variable lists (w/o hashes!)

Replies are listed 'Best First'.
Re^2: Reading and producing variable lists (w/o hashes!)
by bingohighway (Acolyte) on May 01, 2009 at 10:49 UTC
    I have a series of templates in a pseudocode style, used for config file generation for repeated and varying user setups. The pseudocode style has a pre-processor command style, e.g.
    #define $var = "hello" #if($var = "hello") include this text in config file also include the word $var as an inserted word #endif
    I have managed to get the evaluation of the #if statements sorted, but the actual definition of the variables is a bit more of a pain.

    The reason for not using hashes is to avoid having to process each line of config text, looking for the $variable. Also, using the #if statements with hashes, I'd have to process the $variable and turn it into $list_of_variables->{$variable}.

    Does that make sense? Do you agree? :-)


      Not to be difficult, but why not use cpp instead of reinventing the wheel? Or perhaps a templating engine (there's one or two on CPAN, I hear)?

      I agree with roboticus about the templates and would add that there are one or two config modules that are more than happy to generate files too.

      So, imho, it would be wise to at least have a look at the prior art.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://761249]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-03-20 19:19 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.