RecursionBane has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, Monks!
I am trying to solve a problem with a rather stringent set of limitations. Having tried fruitlessly for several days, I turn to your wisdom to accomplish this.
Please keep in mind that I have greatly simplified the inputs and outputs in order to make it easy for you to read.
This package contains many hashes (simplified below to only contain one hash with one key):
Am I going about this the right way? Any suggestions from your collective wisdom would be much appreciated.
~RecursionBane
Please keep in mind that I have greatly simplified the inputs and outputs in order to make it easy for you to read.
This package contains many hashes (simplified below to only contain one hash with one key):
I wish to allow the user to craft any shell command that uses this variable, like so (again, simplified):> cat TEST_PACKAGE.pm package TEST_PACKAGE; use base 'Exporter'; our @ISA = qw(Exporter); our @EXPORT_OK = qw(%TEST_HASH); our %TEST_HASH; $TEST_HASH{'TEST_KEY'} = 'TEST_VALUE'; 1;
I've created multiple versions of this program to no avail:xterm> ./test.pl '/bin/touch $TEST_HASH{'TEST_KEY'}' # Would create + a touchfile called TEST_VALUE xterm> ./test.pl 'echo Test key contains $TEST_HASH{'TEST_KEY'}' # Wo +uld echo TEST_VALUE
In usage:> cat test.pl #!/usr/bin/perl my @command = @ARGV; use TEST_PACKAGE qw(%TEST_HASH); my $command_string; for (my $i = 0; $i < scalar(@command); $i++ ) { # Interpret each word in the command string and substitute kno +wn variables $command_string = $command_string . " " . ( sprintf "%s", $com +mand[$i] ); } print "\nExecuting command: $command_string\n"; system "$command_string";
I think the problem might be because Perl does not interpolate hash values inside quotes.xterm> ./test.pl 'echo Test key contains $TEST_HASH{'TEST_KEY'}' # O +ne of many trials, with varying escape characters tried Executing command: echo Test key contains $TEST_HASH{TEST_KEY} Test key contains {TEST_KEY}
Am I going about this the right way? Any suggestions from your collective wisdom would be much appreciated.
~RecursionBane
|
---|
Back to
Seekers of Perl Wisdom