in reply to Get variables from txt file

This is going to eventually deteriorate into a bunch of hacks where you provide ways to escape $ characters, and address other complications such as whitespace , or will grow to a full fledged tokenizing / parsing system. You probably don't want to live with the limitations and mess that the first scenario will become, and probably don't want to invest the time in the second scenario.

Unless you really want to reinvent this wheel because no other wheel out there fills your need well enough, go with a module like Config::General. This distribution provides variable interpolation via Config::General::Interpolated, which is included when you install Config::General. With Config::General, your solution could look like this:

use strict; use warnings; use Data::Dumper; use Config::General; my $c = Config::General->new( -ConfigFile => \*DATA, -InterPolateVars => 1, ); print Dumper {$c->getall()}; __DATA__ V1=/home/user V2=$V1/test V3=$V2/file.txt

Here is the output that will produce:

$VAR1 = { 'V1' => '/home/user', 'V2' => '/home/user/test', 'V3' => '/home/user/test/file.txt' };

...and then you're done and can move on to the real stuff. ;)


Dave