Do you know how to interpolate a variable that is read from a file? Below is my situation:
1. I have up to a hundred of simple hashes like this:
All the hashes have the same keys. To keep the main source file clean, I leave all these hashes in a single file and require it at the head of the main source file.my %act = ("food" => "eat it", "drink" => "drink it", "Perl" => "play it");
2. In the main source file, I use all these hashes in this way:
but, the $out variable is so long that I want to keep it in another file because there are more than hundred of hashes. I do this by producing a one-line file like this:my $item = "Perl"; my $out = "-p $act1{$item} -p $act2{$item} -p ... ";
-p $act1{$item} -p $act2{$item} ...
then I read this line into $out variable in the main source file. I thought Perl can interpolate the variable with their value. But, it turns out that Perl doesn't do this. The variable which contains the contend read from the file just keep all the variable as it is.
Er, I don't know if I explain this problem clear enough. And could someone help me out of this?
In reply to Interpolation of variables read from a file by phio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |