Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble With Variables and Data, Please Help! 1

Status
Not open for further replies.

goliath

MIS
Aug 18, 1999
62
US
Help!

I guess I'm stumped on some useage for variables.

I've written a menu in perl. The menu script reads from a text file to determine what to display on the menu and then what to do for that selection.

Sample of menu data file($description, $command):
Copy data, Copy $from $to
Delete Data, Delete $data

My menu script reads in the menu data and uses split to put the description into $description and the command into $command.

In my menu script I've defined:
$from = "C:";
$to = "D:";

Then I use:
system ($command);
Which gives this for output:
Copy $from $to
instead of what I had hoped for:
Copy C: D:

Any help desperately appreciated. I can reformat my data of course but I'm stumped on how to get it to change the variables in the data to the value of the varialbes in the script.

-Goliath
 
the way you have it set up you will have to do something a little more convoluted to get the $to and $from variables interpolated correctly:
Code:
system(eval "\"$command\"");
jaa
 
I've been trying to simulate this in a smaller script which turned out to be surprisingly difficult. Yet I came up with this:

$x = "DEF";
$y = "ABC \$x";
print "$y";

- gives "ABC $x" instead of "ABC DEF".

I'm wondering if there's a way I could use regex and substitute any variables with the appropriate variable..

So for anything starting with $ to end of word replace with the same actual variable data. Hmmm... Just thinking out loud. I don't get to go home tonight until I get this working =
Thanks in advance!
 
Ooooh! Looks like eval will work!!! Thank you thank you thank you!

Justice41, you've probably answered every one of my "I'm stumped" questions - Just let me know if you need me to mail you a case of beer someday =)

Thanks again!

-Goliath
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top