I brought this up briefly in the chatterbox and
Bart got me started in the right direction. His solution was to store a reference to the variable as the hash value, which worked as he said it, but didn't work as I need it to.
I have a hash that I am looking to store function parameters and some text in. Some of the parameters are stored elsewhere in the script as scalars and would need to be evaluated at the time of use.
How would I do something like this:
%hash = (
'command1' => 'command_name -n $var1 -p $var2
+'
)
$var1 = 'foo';
$var2 = 'bar';
system ($hash{'command'});
I am looking for a way to have $var1 and $var2 be replaced with their respective values. Is this possible? Another twist, the solution would have to be compatible with Perl versions 4 and up. Why 4? Because that's what my customer uses at the moment. :-|
Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.