phio has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interpolation of variables read from a file
by Corion (Patriarch) on Dec 04, 2007 at 07:29 UTC | |
by phio (Acolyte) on Dec 04, 2007 at 10:09 UTC | |
|
Re: Interpolation of variables read from a file
by ikegami (Patriarch) on Dec 04, 2007 at 07:26 UTC | |
|
Re: Interpolation of variables read from a file
by wind (Priest) on Dec 04, 2007 at 07:32 UTC | |
|
Re: Interpolation of variables read from a file
by phio (Acolyte) on Dec 04, 2007 at 07:49 UTC |